VS code not recognize the Python package I installed on my Mac

Viewed 12194

I tried to run a python script file on Visual Studio. But the terminal keep pop up saying that I don't have the package installed... I don't know what is going on. I installed Python through homebrew and install all the package through pip3. I even find the path for all the package I have installed, and it's still not working.. I switched between multiple interpreter, and none of them worked, all said my package is not installed.. but it's clearly my package is installed... I even create a new py file to run pandas, and it worked.. Can someone help me with this? This is driving me crazy.. enter image description here enter image description here

2 Answers

It just because you had chosen the wrong python environment in VSCode.

You said you had created a python file to run pandas and it worked. This means you had installed the package 'pandas' and it worked. But you haven't chosen this environment in your VSCode.

In the terminal:

By command "pip3 --version" to check which pip you are using.

By command "python3" -> "import sys; sys.executable" to check which python you are using.

By command "python3" -> "import sys; sys.path" to check which 'site-package' the interpreter searching for.

From your description, you are using the pip which under '/usr/local', install the packages under '/usr/local/lib/python3.7/site-packages', using python interpreter of '/usr/local/bin/python3'. This is the default python interpreter because of the system environment variables settings. But in VSCode you haven't chosen this environment.

Solution:

Choose an environment or create a virtual environment(recommend). Activate the environment(Ctrl+Shift+`), by the command 'pip3 --version' to check which pip3 you are using, then install the package you want to import.

If you installed python via homebrew try using homebrew to install pandas instead of pip. I've seen things before that they get linked. I would just recommend using pip to uninstall pandas first so there is only package.

Related