5

Tried to import pandas in VS Code with

import pandas

and got

Traceback (most recent call last):
  File "c:\Users\xxxx\hello\sqltest.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:\Users\xxxx\hello> pip3 install pandas

Requirement already satisfied: pandas in c:\users\xxxx\hello\.venv\lib\site-packages (1.1.0)
Requirement already satisfied: pytz>=2017.2 in c:\users\xxxx\hello\.venv\lib\site-packages (from pandas) (2020.1)
Requirement already satisfied: numpy>=1.15.4 in c:\users\xxxx\hello\.venv\lib\site-packages (from pandas) (1.19.1)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\xxxx\hello\.venv\lib\site-packages (from pandas) (2.8.1)
Requirement already satisfied: six>=1.5 in c:\users\xxxx\hello\.venv\lib\site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)

Tried:

sudo pip install pandas

and got

(.venv) PS C:\Users\xxxx\hello> 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:\Users\xxxx\AppData\Local\Microsoft\WindowsApps\python.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:\Users\xxxx\hello> 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:\Users\xxxx\hello> 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
nilsinelabore
  • 3,061
  • 10
  • 30
  • 83

5 Answers5

12

It's easier than we imagine:

enter image description here

This image explains how to solve this problem.

Jeremy Caney
  • 6,191
  • 35
  • 44
  • 70
dav salrangel
  • 121
  • 1
  • 3
2
  1. Download anaconda interpreter from this link
  2. After installation, open anaconda prompt (anaconda3) and execute this code conda install ipykernel. It will install all necessary packages.
  3. Restart vs code and change interpreter to base conda and voala!
Grimmret
  • 41
  • 3
  • This solved my problem. Thanks. I ran it in Visual Studio 2022 (Community Edition) though. One thing I see is that it opens a Python exe command prompt, to show the results. Any way I can see the results in Visual Studio itself? Thanks for the answer. – RedBottleSanitizer Feb 26 '22 at 22:43
  • 1
    Hmmm... It could be your file extension, if it ends with (.py) it will open on python.exe. Try changing it to (.ipynb). – Grimmret Mar 01 '22 at 14:55
  • Changing to ipynb didn't solve it. I am looking to see the results for the Python program in Visual Studio itself. Is that doable? – RedBottleSanitizer Mar 04 '22 at 03:30
1

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:

pip --user

Display() in Python

nilsinelabore
  • 3,061
  • 10
  • 30
  • 83
1

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:\Users\xxxx\hello> 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

Jessy Guirado
  • 220
  • 1
  • 7
1

I have just run VSCode as administrator!