37

I've been trying to use the packages pandas, numpy, matplotlib, seaborn in my "Visual Studio Code", but the program keeps showing me the following message:

"import pandas could not be resolved from source Pylance(reportMissingModuleSource)"

Previously to Visual Studio Code I installed "Anaconda" to use Jupyter, and now it says that i have the existing packages (pandas, numpy...) but keeps appearing this message that doesn't allow me to use pandas in my Visual Studio.

Anyone could help me to solve this issue?

I tried installing again all the packages to check if they didn't exist but apparently are installed all of them but in another route. I can't find how is the way to put them so the Visual Studio Code recognizes them and I can use them.

15 Answers 15

48

I also received similar an error on my IDE VSCode and currently using mac m1 .First we need to make sure that the python3 interpreter version from terminal version is the same with our python version selection in VSCode.

  1. open terminal.
  2. type 'python3'
  3. then you will see your python version.(my python3 version is 3.9.12)

python3 version

  1. open your IDE VSCode

  2. open any/current folder that related to python project on IDE VSCode

  3. Check your python version at the bottom right on IDE VSCode (in my case the python version is 3.10.64)

  4. change or switch VSCode python version from 3.10.64 to 3.9.12 (same with your python version on your pc)

  5. done

Sign up to request clarification or add additional context in comments.

1 Comment

GOLD. GOLD. GOLD.
13

First, Uninstall pylance extensions from your VS Code. Close the VS Code, Reopen the VS Code, install pylance again.

It works for me!

2 Comments

No need to close VSCode, just uninstall, reinstall and you are good to go!
Uninstalling Pylance removes the squiggles, but re-installing it gets the squiggles back again. I have tried with VS Code restart, and without restart between re-installs. Same issue. Installing Pylance gets the squiggles back. Interpreter is correct, code works properly, but the squiggles persist.
8

Also, you can click on the interpreter version at the bottom left corner of the screen (Vs.code 2022) it should show a dropdown menu with a list of the available and selected python interpreter. Click on add interpreter path and paste the path to the python interpreter with all the required modules installed and click enter. This should resolve the problem.

1 Comment

In VSCode 1.88.0 the interpreter version is now at the bottom right. I clicked it, then clicked "Enter interpreter path", then added /home/nick/environments/fpl_env/bin/python3, which is the path to the Python virtual environment I want to use (in Ubuntu in WSL2). Even though that redirects to /usr/bin/python3, which is the same Python executable I had selected previously, it enabled my PIP-installed libraries to be found.
5

I encountered this problem in VSCode under remote to WSL2 of Windows 10. The Python version is correct as interpreter (3.9.13) and the terminal in VSCode is also under the same envs (ie. VSCode ran "conda activate xx" and (xx) is shown in prompt)

Originally, I tried to install the pandas by the following command.

sudo apt-get install python3-pandas

Pandas was installed successfully as stated in the terminal but the problem is still there.

When I try to install pandas by the following command, the problem solved.

pip install pandas

1 Comment

I did this in the reverse order and it worked for me, originally installed with pip, and then your apt-get.
2

I also had this problem and it was because of version mismatches.

I had installed Python AND Anaconda. If anyone else has done this and gets this error, you need to uninstall both. Then install Anaconda only; Python (the compatible version) is installed as part of that process.

See https://docs.anaconda.com/anaconda/install/windows/

Comments

1

Another way I solved this issue having followed every other installation process to the letter was deactivating Pylance. Works a (py)charm now.

Comments

1

You should install pandas again using current active python interpreter. For example if your current interpreter is located in:

C:\Users\[username]\AppData\Local\Programs\Python\Python311

then you should install pandas using this command:

C:\Users\[username]\AppData\Local\Programs\Python\Python311\python.exe -m pip install pandas

Note that you can find your current interpreter by clicking on the python version at the bottom right of Vscode.

Comments

1

You should choose the right version of python at the bottom right of VSCode with the python version that you have installed.

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
This is correct, as the problem described by the OP usually results from the wrong Python interpreter being specified. You can select the Python interpreter for the virtual environment where you have installed Pandas by clicking in the lower right as shown here and selecting it up top. For details, see Using Python environments in VS Code
0

I re-entered the path to Python interpreter and warning disappeared. Hope that helps you.

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
This person is referring to the environmental path that is stored in your pc.
0

My VSCode Python extension had in its settings, a default interpreter path that was an invalid leftover. Even if the interpreter selected at the bottom right for running the file was the correct one, this caused the problem reporter to encounter issues.

I went into settings and reset the entry for python.defaultInterpreterPath.

Comments

0

Maybe the environment path for python was changed, and thus the problem.

For me it was: 'C:\Program Files\Python311\Scripts', and not 'C:\Program Files\Python311'

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

In my case (Mac User), I have 2 python versions (version2, version3)

VScode looks for version2, so I need to install pandas for version3 by

pip3 install pandas

then change VScode path setting to the python3 installation folder. You can check the folder by terminal command:

python3 -version

Then go to VScode setting and type Python Path in search box, and you will see Default Interpreter Path, then paste the new path of your python3

for your reference my path is /Library/Frameworks/Python.framework/Versions/3.10/bin/python3

Comments

0

Check the version of your python being run from the IDE as stated in this answer: VS Code: ModuleNotFoundError: No module named 'pandas'

Comments

0

If you have ensured that Python version at the bottom right of VSCode and Python version installed in your system is the same and are still facing this issue -

Enter this in your VS code terminal -

python -m pip install <package_name>

This worked for me. Hope its useful.

Comments

0

You can simply keep note of all your used packages in this project by running:

pip freeze > requirements.txt

Then delete the venv folder, and create new venv folder and reinstall all the packages from requirements.txt by running:

pip install -r requirements.txt

That's how I easily solve "module not resolved" issue when working on python projects.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.