Home > Back-end >  Can't figure out "unable to import [module]" in VSCode
Can't figure out "unable to import [module]" in VSCode

Time:04-19

I've recently swapped drives on my notebook and decided on a completely fresh install. When setting up VSCode for a new python project, I installed the latest version from python's website, added the appropriate environment variable to the path, removed the length cap for the pathname too, and all that. python environment variable added to Path But still, every time I import NumPy or any other module for that matter, it throws an error saying "unable to import [module]". vscode error I don't know what else to do, VSCode even recognizes the interpreter (see image 3). python interpreter selected in vscode Tried setting up a venv aswell, end up getting the same error.

CodePudding user response:

This is how I normally set up a project and it always works.

(open directory in VSCode)

Within the VSCode Terminal

python3 -m venv .venv
source .venv/bin/activate

At this time vscode should automatically detect that there is a new virtualenv and ask you to use it.

If it doesn't you can use the CMD Shift P (CTRL Shift P) search for "Select Python Interpreter" and specify the path.

CodePudding user response:

Did you install Numpy in the virtual environment (if you are using one)?

Try to list your installed packages in vscode terminal

python -m pip list

If numpy does not appear, install numpy with:

python -m pip install numpy

Does it work when you run the code? Or is this just a pylint problem?

  • Related