Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import pandas after pip install pandas

I run the following command to install pandas via pip:

sudo pip install pandas --upgrade

which outputs

Requirement already up-to-date: pandas in /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
Requirement already up-to-date: numpy>=1.7.0 in /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from pandas)
Requirement already up-to-date: python-dateutil>=2 in /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from pandas)
Requirement already up-to-date: pytz>=2011k in /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from pandas)
Requirement already up-to-date: six>=1.5 in /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from python-dateutil>=2->pandas)

However, when I use python3 in the command line, I cannot import pandas:

$ python3
>>> import pandas
>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'pandas'

It appears that this is in the correct location, as

which python3 

is in the following location:

/opt/local/bin/python3

Executing within python3

 >>> import sys
 >>> print(sys.version)

outputs

'3.4.5 (default, Jun 27 2016, 04:57:21) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]'

Why can't I import pandas?

EDIT: I'm using pip version pip3:

pip --version

outputs

pip 8.1.2 from /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
like image 719
ShanZhengYang Avatar asked Oct 18 '22 05:10

ShanZhengYang


1 Answers

Looks like your OS uses pip2 by default. This could be checked by typing:

$ pip --version
pip 8.1.2 from /usr/local/lib/python2.7/dist-packages (python 2.7)

Try to use pip3 command like that:

sudo pip3 install pandas --upgrade
like image 97
frist Avatar answered Oct 21 '22 02:10

frist