简体   繁体   中英

ImportError: No module named pandas. Pandas installed pip

i use mac terminal to check my package:

pip list

i can find all packages include pandas

but when i

import pandas

it told me:

ModuleNotFoundError: No module named 'pandas'

by the way, i have python2 and python3 in my mac, they are not the same directory,i suspect python didn't find the path of pandas

First of all, install virtualenv inside your project folder to secure your project directory to avoid conflict with your other packages.

pip install virtualenv

After installing this run this command one by one inside your root project directory:

virtualenv venv
source venv/bin/activate

Now Your directory is secure and you can install your required packages inside.

pip install pandas

and others as you required.

Because you have installed virtualenv and running as secure it will not conflict with other outside packages.

Use this all steps one by one. I hope it will work for you to avoid such error.

Thanks.

Try to install pandas using pip and pip3.

pip install pandas

pip3 install pandas

A suggestion, use pyenv and set a python version for your local directory.

If python v2.7 is already installed, then to install numpy and pandas for v2.7. Run the below commands :

for Ubuntu / Linux -

sudo apt-get install python-numpy
sudo apt-get install python-pandas

If python v3 is already installed, then to install numpy and pandas for v3. Run the below commands :

for Ubuntu / Linux -

sudo apt-get install python3-numpy
sudo apt-get install python3-pandas

I had Python2 and Python3 installed in different directories but I was facing this error because whenI was using the command pip install pandas it was installing pandas in Python2 directories while I was using Python3

So I had two diectories with Python2 --> C:\\Python27 and Python365 --> C:\\Python365 .

To resolve this error:

Run pip install pandas in cmd . If library pandas is already installed you'll see something like following.

C:\Users\vichitrak>pip install pandas
Requirement already satisfied: pandas in c:\python27\lib\site-packages (0.23.4)
Requirement already satisfied: python-dateutil>=2.5.0 in c:\python27\lib\site-packages (from pandas) (2.7.3)
Requirement already satisfied: numpy>=1.9.0 in c:\python27\lib\site-packages (from pandas) (1.14.4)
Requirement already satisfied: pytz>=2011k in c:\python27\lib\site-packages (from pandas) (2018.4)
Requirement already satisfied: six>=1.5 in c:\python27\lib\site-packages (from python-dateutil>=2.5.0->pandas) (1.11.0)

From the output of above command you can see that pandas is installed in Python2 directory ie c:\\python27\\lib\\site-packages (0.23.4)

Run python command in cmd to check which Python version are you running.

C:\Users\vichitrak>python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information. 

You can see that I'm using Python3 while pandas is installed in Python2 directory`

To install the pandas and other libraries in Python3 go to scripts folder in Python3 directory ie C:\\Python365\\Scripts
Open Command Window and run pip install pandas

Or you can use the complete path of pip in Python3 directory on cmd to run the intsall command ie C:\\Users\\vichitrak>C:\\Python365\\Scripts\\pip install pandas

Sometimes, it might be due to an issue with "Microsoft visual C++".

  1. For that, first you need to install the "Microsoft visual C++" using the instructions given in the link: "[ Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat) "
  2. After successful installation, use pip install pandas to install pandas
  3. If pip is not installed, then download thr pandas source package with extension tar.gz and place it in directory wherever you want after extracting. open cmd.exe and navigate to the path where pandas folder is extracted & placed using cd C:/pandas . Then install it using the python setup.py install

Finally you should get the success message as Finished processing dependencies for pandas==0.xx.0

The error I saw is:

File "c:\\SIP\\python\\visualws\\learn1\\pandas_test.py", line 6, in import pandas as pd ModuleNotFoundError: No module named 'pandas'

Executed below command in Windows using Python 3.9.5:

C:\Users\deepy>pip install pandas
Collecting pandas
  Downloading pandas-1.2.4-cp39-cp39-win_amd64.whl (9.3 MB)
     |████████████████████████████████| 9.3 MB 3.3 MB/s
Collecting pytz>=2017.3
  Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
     |████████████████████████████████| 510 kB 6.8 MB/s
Collecting numpy>=1.16.5
  Downloading numpy-1.20.3-cp39-cp39-win_amd64.whl (13.7 MB)
     |████████████████████████████████| 13.7 MB ...
Collecting python-dateutil>=2.7.3
  Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
     |████████████████████████████████| 227 kB 6.4 MB/s
Collecting six>=1.5
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, pytz, python-dateutil, numpy, pandas
Successfully installed numpy-1.20.3 pandas-1.2.4 python-dateutil-2.8.1 pytz-2021.1 six-1.16.0
WARNING: You are using pip version 21.1.1; however, version 21.1.2 is available.
You should consider upgrading via the 'c:\users\deepy\appdata\local\programs\python\python39\python.exe -m pip install --upgrade pip' command.

It solved the problem and I am able to execute the .py file with import pandas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM