ModuleNotFoundError: No module named 'pandas' in vs code

Viewed 3115

When I'm trying to import pandas in vs code, I have the following error:

ModuleNotFoundError: No module named 'pandas'

I went to cmd and typed: pip3 install pandas and it got successfully installed showing following message:

Requirement already satisfied: pandas in c:\users\nitis\anaconda3\lib\site-packages (1.1.3)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\nitis\anaconda3\lib\site-packages (from pandas) (2.8.1)
Requirement already satisfied: pytz>=2017.2 in c:\users\nitis\anaconda3\lib\site-packages (from pandas) (2020.1)
Requirement already satisfied: numpy>=1.15.4 in c:\users\nitis\anaconda3\lib\site-packages (from pandas) (1.19.2)
Requirement already satisfied: six>=1.5 in c:\users\nitis\anaconda3\lib\site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)

Please suggest what to do

3 Answers

There are a couple different ways that this can happen.

  1. You are using a Python 2 Interpreter in VSCode
  2. You are using a Python 3 installation which isn't Anaconda.

To solve this, I would recommend checking which python interpreter you are using using the following steps:
Go to View >> Command Palette >> Search for Python: Select Interpreter
Then check which interpreter you are using.

According to the information you provided, the reason is that the environment used in the lower left corner of VS Code is different from the terminal. You could use the following methods:

Method 1. Since the module "pandas" is installed in "Anaconda", please select the "conda" environment in the lower left corner of VS Code to ensure that the Python environment used is the same as that of the terminal.

Method 2. Use the shortcut key Ctrl+Shift+` to open a new VS Code terminal, it will automatically enter your currently selected Python environment (the lower left corner of VS Code). Then we can install the module "pandas" in the this environment.

check:

We can use the command "pip --version" to check the source of the module installation tool "pip", the module is installed in this location:

enter image description here

The command "pip show pandas" can check whether the module installation location is consistent with the Python environment displayed in the lower left corner of VS Code:

enter image description here

Reference: Python environment in VS Code.

Its because of PYTHONPATH issue . if you try to install pip install "module",it says that already satisfied but ,when you run the program the error occurs as modulenotFoundError In vscode, So I did uninstall the python interpreter ,and reinstall in specific path so that I can remember.

And go to environment variable ,path variable add new path ,where you installed python.exe and also add scripts and sitepackages. and also go to system variable ,path variable see if path is already added or not ,otherwise add it there too. Restart the vscode It should work.

And I also run command in commandprompt as pip install "module". It did work for me.

Related