Visual Studio Code windows , Python Pandas . No module named pandas
Solution 1
It seems that the module pandas is installed in a virtual envorinment which you are not accessing via VS Code.
I'd suggest you to install pandas in default python as well via
pip install pandas
This way the VS Code will work it out just fine.
Else:
In VS Code console, activate the virtual enviornment in which you have installed the pandas module, and then run it. It should work
Solution 2
I had a similar problem in VS Code. I was not able to find modules like Pandas, Selenium etc. Imports were underlined with a red colour.
Fixed the issue by changing the version of Python 3.7.3 64-bit
to version 3.8.1 64-bit
.
Procedure:
- Hit
Ctrl + Shift + P
- Select Python: Select Interpreter
- Choose the latest installed version of Python (no more red underlines)
Solution 3
@Davdei It is good practice to work with a virtual environment, so you can test against different versions of Python. To get the list of available Python interpreter use (⇧⌘P) on Mac or alternatively, you can click the status bar
Solution 4
This can also happen when the specific module is not installed using pip3, so simply installing the module using pip3 would solve the problem.
pip3 install pandas
Solution 5
I had a same problem and none of the above seems to solve the issue. Later found that it has to do something with the python interpreter. I created virtual environment and my terminal can see it, but not the python script file where the code exists. Therefore, it must be an interpreter problem. Changed the interpreter to correct location:
cd .venv/Scripts/
./activate
(Here ".venv" is my virtual environment name. It could be different too (eg. "venv")
With an existing installation via pip:
pip3 install pandas
This solved the problem.
Davdei
Updated on June 02, 2021Comments
-
Davdei almost 3 years
I set the variables for Env. All necessary modules for Pandas operation are installed by pip. I wanted to run the code to display it in "Output". I run with: Alt + CTRL + N(or right click -> Run code).
In output returns the message:
But when I run in the terminal (right click -> Run Python File in Terminal), the code works correctly.
I would like the code to run correctly in output(right click -> Run code), not in the terminal. Any suggestions?
-
Davdei over 5 yearsIts works. I installed pandas in default Python and this is works. But why it does not work in a virtual environment ? Always activates the virtual environment before.
-
Mohammad Zain Abbas over 5 yearsVS Code is not configured to use the virtual environment that you created. It could only use the default Python shell. That's why it was not working.
-
Mohammad Zain Abbas over 5 yearsWell, I am glad to be of any help to you :) you can accept the answer so others may get helped also :) thanks
-
Davdei over 5 yearsThanks You for Your help. I must resolve problem with environment configuration in VS Code. For now I will be used default Python. Best regards:)
-
DarkHark about 2 yearsI had to use F1 to open my command palette. Not sure why the other shortcut did not work.
-
Decapitated Soul about 2 yearsThis helped me solve the problem.