16

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.

Joan Cheto
  • 161
  • 1
  • 1
  • 3

11 Answers11

23

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

khoi
  • 940
  • 1
  • 14
  • 29
6

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.

Kev_Dev1
  • 97
  • 1
  • 8
4

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
kebenny
  • 41
  • 3
  • I did this in the reverse order and it worked for me, originally installed with pip, and then your apt-get. – Cigol Jun 23 '23 at 09:21
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/

KymBo
  • 21
  • 2
1

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

  • 1
    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](/help/how-to-answer). – Community Mar 25 '23 at 07:51
  • 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](https://ibb.co/zWckTwP) and selecting it up top. For details, see [Using Python environments in VS Code](https://code.visualstudio.com/docs/python/environments) – Mark Hansen Apr 08 '23 at 19:46
0

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

Damian
  • 17
  • 1
  • 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](/help/how-to-answer). – Community Mar 30 '22 at 14:51
  • This person is referring to the environmental path that is stored in your pc. – Marja van der Wind Feb 09 '23 at 17:31
0

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

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.

Cloud
  • 938
  • 1
  • 8
  • 24
0

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.

RezA
  • 103
  • 1
  • 8
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'

bko00
  • 39
  • 7
  • 1
    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](/help/how-to-answer). – Community May 07 '23 at 20:47
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

Natt
  • 16
  • 2