install and import pandas in vscode

Viewed 69

I am a very beginner for vscode and python and computer stuff in general.

I am having trouble importing pandas into vs code, and none of the previous posts was helpful for me since I literally can't understand it and can't follow their steps.

I am gonna show you what I have done so far.

First, I open the vscode and open terminal (powershell)

Second, I type pip3 install pandas and it successfully install pandas For example, I ran that command again, it gave me "Requirement already satisfied" enter image description here

Third, as it seemed pandas is installed correctly, I type py to open python in the terminal and type import pandas as pd

But, it gave me : import pandas as pd Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'pandas'

enter image description here

I really don't know why it is happening and what to do to fix this.

I will appreciate any help you can give me.

Thanks,

2 Answers
  • try pip install pandas instead of pip3
  • use cmd or git bush instead of powershell
  • use virtual environments in the current working directory:
  1. open vscode on new folder
  2. Terminal > New Terminal: (make shure it's cmd not Powershell)
  3. pip install pipenv (on cmd)
  4. pipenv install pandas
  5. close vs code, open it again on the same folder
  6. Terminal > New Terminal (cmd)
  7. pipenv shell
  8. py

Make sure you are using the same interpreter as the one you installed the pandas library with.

Run the following code to print out the python interpreter you are currently using

import sys
print(sys.executable)

enter image description here

Copy the full path of the interpreter and install the pandas library for it using the command

C:\Users\Admin\AppData\Local\Programs\Python\Python310\python.exe -m pip install pandas

Modify the above path to the path you just got

It can also be done in the interactive window of the terminal

enter image description here

Related