VS Code: ModuleNotFoundError: No module named 'pandas'
Question:
Tried to import pandas
in VS Code with
import pandas
and got
Traceback (most recent call last):
File "c:Usersxxxxhellosqltest.py", line 2, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
Tried to install pandas
with
pip install pandas
pip3 install pandas
python -m pip install pandas
separately which returned
(.venv) PS C:Usersxxxxhello> pip3 install pandas
Requirement already satisfied: pandas in c:usersxxxxhello.venvlibsite-packages (1.1.0)
Requirement already satisfied: pytz>=2017.2 in c:usersxxxxhello.venvlibsite-packages (from pandas) (2020.1)
Requirement already satisfied: numpy>=1.15.4 in c:usersxxxxhello.venvlibsite-packages (from pandas) (1.19.1)
Requirement already satisfied: python-dateutil>=2.7.3 in c:usersxxxxhello.venvlibsite-packages (from pandas) (2.8.1)
Requirement already satisfied: six>=1.5 in c:usersxxxxhello.venvlibsite-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
Tried:
sudo pip install pandas
and got
(.venv) PS C:Usersxxxxhello> sudo pip install pandas
sudo : The term 'sudo' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ sudo pip install pandas
+ ~~~~
+ CategoryInfo : ObjectNotFound: (sudo:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I also tried to change the python path under workspace settings following this answer. with C:UsersxxxxAppDataLocalMicrosoftWindowsAppspython.exe
which is the python path I found in Command Prompt using where python
but didn’t work.
Then I tried
python -m venv .venv
which returned
(.venv) PS C:Usersxxxxhello> python -m venv .venv
Error: [Errno 13] Permission denied: 'C:\Users\xxxx\hello\.venv\Scripts\python.exe'
Update:
Tried
python3.8.5 -m pip install pandas
and returned
(.venv) PS C:Usersxxxxhello> python3.8.5 -m pip install pandas
python3.8.5 : The term 'python3.8.5' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python3.8.5 -m pip install pandas
+ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (python3.8.5:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Answers:
Seems to have worked with
pip install pandas --user
in Command Prompt.
Additional note:
For IPython.display
,
pip install IPython--user
in Command Prompt, then
from IPython.display import display
in VS Code.
Helpful links:
The solution seems fairly simple! First things first though!
From looking at your post, you seem to have followed a guide into installing Pandas
. Nothing is wrong about that but I must point out first based on your information that you provided to us, you seem to run Windows Powershell PS C:Usersxxxxhello>
and the error format matches Powershell
. Therefore, sudo
isn’t recognized because sudo
is the admin command for Unix-based
systems like Debian, Ubuntu, and so on
which is why it’s not a valid command!
But here’s how to properly install: (I assume you’re running Windows but if that’s not the case, correct me and Ill give you the Unix version!)
1 – Windows key, search up CMD
and run it as administrator
this is important to avoid permissions issues!
2 – Run pip3 install pandas
OR python3 -m pip3 install pandas
It’s easier than we imagine:
This image explains how to solve this problem.
I have just run VSCode as administrator!
- Download anaconda interpreter from this link
- After installation, open anaconda prompt (anaconda3) and execute this code
conda install ipykernel
. It will install all necessary packages.
- Restart vs code and change interpreter to base conda and voala!
I had the same problem and running the below command solved it:
pip3 install pandas --upgrade
The problem (at least in my case) was that I have installed a package under the default Python version but I have set the interpreter for the different Python version in Visual Studio Code (VS Code).
There are 2 options to resolve this.
- Change the VS Code Interpreter: VS Code -> View -> Command Palette… (Ctrl+Shift+P) -> Python: Select Interpreter -> select "Python: Select Interpreter" (or Enter) -> select an interpreter based on our chosen Python version under which you have installed the package.
- Install package under the correct Python version which means to change your default Python version and repeat the process of installation again.
To change your default Python version (for Windows 10):
Right click on This PC -> Properties -> Advanced System Settings (in the right panel) -> Environment Variables -> System variables (the bottom part of the window) -> double-click on "Path" -> Select the 1st row for the wanted Python version and move it up and then do the same with the 2nd row. I recommend to restart (close and open again) your Command Prompt session if you want to see/work with the new default Python version.
Note on installation: Following command (in Command Prompt) worked for me:
pip3 install pandas –user
If you have multiple versions of python installed and/or have something like acaconda installed, you’ll have conflicts with the interpreter location in vscode.
To change the settings in vscode:
Ctrl + P
Search for python: select interpreter
and then select ‘recommended’ option and it should work again.
If you don’t want to use Anaconda, I’ve tried many things and only this worked for me.
In windows search, find "This PC", right click and click properties-> Advanced system settings -> Advanced(tab) -> Environment viriables -> Path
For me
Add or Edit Path to: C:Usersyour_user_nameAppDataLocalProgramsPythonPython310Scripts
I had the same issue using vscode on ubuntu 22.04 with anaconda3. The solution for me was: Open settings, type 'python: default Interpreter Path'
and enter the path where the python executable is /home/user/anaconda3/bin/python
Tried to import pandas
in VS Code with
import pandas
and got
Traceback (most recent call last):
File "c:Usersxxxxhellosqltest.py", line 2, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
Tried to install pandas
with
pip install pandas
pip3 install pandas
python -m pip install pandas
separately which returned
(.venv) PS C:Usersxxxxhello> pip3 install pandas
Requirement already satisfied: pandas in c:usersxxxxhello.venvlibsite-packages (1.1.0)
Requirement already satisfied: pytz>=2017.2 in c:usersxxxxhello.venvlibsite-packages (from pandas) (2020.1)
Requirement already satisfied: numpy>=1.15.4 in c:usersxxxxhello.venvlibsite-packages (from pandas) (1.19.1)
Requirement already satisfied: python-dateutil>=2.7.3 in c:usersxxxxhello.venvlibsite-packages (from pandas) (2.8.1)
Requirement already satisfied: six>=1.5 in c:usersxxxxhello.venvlibsite-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
Tried:
sudo pip install pandas
and got
(.venv) PS C:Usersxxxxhello> sudo pip install pandas
sudo : The term 'sudo' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ sudo pip install pandas
+ ~~~~
+ CategoryInfo : ObjectNotFound: (sudo:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I also tried to change the python path under workspace settings following this answer. with C:UsersxxxxAppDataLocalMicrosoftWindowsAppspython.exe
which is the python path I found in Command Prompt using where python
but didn’t work.
Then I tried
python -m venv .venv
which returned
(.venv) PS C:Usersxxxxhello> python -m venv .venv
Error: [Errno 13] Permission denied: 'C:\Users\xxxx\hello\.venv\Scripts\python.exe'
Update:
Tried
python3.8.5 -m pip install pandas
and returned
(.venv) PS C:Usersxxxxhello> python3.8.5 -m pip install pandas
python3.8.5 : The term 'python3.8.5' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python3.8.5 -m pip install pandas
+ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (python3.8.5:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Seems to have worked with
pip install pandas --user
in Command Prompt.
Additional note:
For IPython.display
,
pip install IPython--user
in Command Prompt, then
from IPython.display import display
in VS Code.
Helpful links:
The solution seems fairly simple! First things first though!
From looking at your post, you seem to have followed a guide into installing Pandas
. Nothing is wrong about that but I must point out first based on your information that you provided to us, you seem to run Windows Powershell PS C:Usersxxxxhello>
and the error format matches Powershell
. Therefore, sudo
isn’t recognized because sudo
is the admin command for Unix-based
systems like Debian, Ubuntu, and so on
which is why it’s not a valid command!
But here’s how to properly install: (I assume you’re running Windows but if that’s not the case, correct me and Ill give you the Unix version!)
1 – Windows key, search up CMD
and run it as administrator
this is important to avoid permissions issues!
2 – Run pip3 install pandas
OR python3 -m pip3 install pandas
It’s easier than we imagine:
This image explains how to solve this problem.
I have just run VSCode as administrator!
- Download anaconda interpreter from this link
- After installation, open anaconda prompt (anaconda3) and execute this code
conda install ipykernel
. It will install all necessary packages. - Restart vs code and change interpreter to base conda and voala!
I had the same problem and running the below command solved it:
pip3 install pandas --upgrade
The problem (at least in my case) was that I have installed a package under the default Python version but I have set the interpreter for the different Python version in Visual Studio Code (VS Code).
There are 2 options to resolve this.
- Change the VS Code Interpreter: VS Code -> View -> Command Palette… (Ctrl+Shift+P) -> Python: Select Interpreter -> select "Python: Select Interpreter" (or Enter) -> select an interpreter based on our chosen Python version under which you have installed the package.
- Install package under the correct Python version which means to change your default Python version and repeat the process of installation again.
To change your default Python version (for Windows 10):
Right click on This PC -> Properties -> Advanced System Settings (in the right panel) -> Environment Variables -> System variables (the bottom part of the window) -> double-click on "Path" -> Select the 1st row for the wanted Python version and move it up and then do the same with the 2nd row. I recommend to restart (close and open again) your Command Prompt session if you want to see/work with the new default Python version.
Note on installation: Following command (in Command Prompt) worked for me:
pip3 install pandas –user
If you have multiple versions of python installed and/or have something like acaconda installed, you’ll have conflicts with the interpreter location in vscode.
To change the settings in vscode:
Ctrl + P
Search for python: select interpreter
and then select ‘recommended’ option and it should work again.
If you don’t want to use Anaconda, I’ve tried many things and only this worked for me.
In windows search, find "This PC", right click and click properties-> Advanced system settings -> Advanced(tab) -> Environment viriables -> Path
For me
Add or Edit Path to: C:Usersyour_user_nameAppDataLocalProgramsPythonPython310Scripts
I had the same issue using vscode on ubuntu 22.04 with anaconda3. The solution for me was: Open settings, type 'python: default Interpreter Path'
and enter the path where the python executable is /home/user/anaconda3/bin/python