[SOLVED] How do i change the directory from which i import modules?

Issue

This Content is from Stack Overflow. Question asked by Joaquin Quezada

I’m new to python and programming in general.

I’ve been using Visual Studio 2022 to learn python for the last 2 weeks, and I’ve hit a roadblock. I cannot for the life of me find a way to permanently change from where I import modules.
I know that pip installs modules on

C:UsersjoaquAppDataLocalPackagesPythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0LocalCachelocal-packagesPython310site-packages

but when I try to import a module I’ve installed, python or Visual Studio or whatever the problem is, can’t find the module, and it says “No module named ‘(module name)'”.

How do I fix this?



Solution

Sometimes the IDE is using a different installation of Python than the one you want to use. (It may have come with the IDE.)

In this case you need to know how to change the interpreter in the IDE that you use or how to install packages in the IDE’s version of Python.

in Visual Studio Code, you can go to to File -> Preferences -> Settings, write python in the search area, and copy and paste the path for the Python that you want into the Python: Default Interpreter Path field.

image to make every thing clear


This Question was asked in StackOverflow by Joaquin Quezada and Answered by Mohammed almalki It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?