Pandas is installed but import pandas throws error

1.7k Views Asked by At

Some information about version i am using

pip -V

Result:

pip 6.1.1 from /usr/local/lib/python3.4/site-packages (python 3.4)

Next:

python -c "import sys,pip;print(sys.version,pip,pip.__version__)"

Result:

('2.7.6 (default, Mar 22 2014, 22:59:56) \n[GCC 4.8.2]', <module 'pip' from '/usr/lib/python2.7/dist-packages/pip/__init__.pyc'>, '1.5.4')

I have installed pandas by

sudo pip install pandas
sudo easy_install pandas

I can see pandas in my system using

pip list

Result

certifi (14.5.14)
nltk (3.0.2)
numpy (1.9.2)
pandas (0.16.1)
pip (6.1.1)
pyparsing (2.0.3)
python-dateutil (2.4.2)
pytz (2015.2)
setuptools (2.1)
six (1.9.0)
tornado (4.1)

But when I import it, it throws error

python

>>> import pandas

Error

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

Pandas is installed but why it is not working and how to make pandas work with my python interpreter

1

There are 1 best solutions below

0
On

I don't see why you expect your Python 2 and Python 3 installations to be in sync. The output from pip -V clearly displays that it is running on Python 3.4, and the output of python -c "import sys,pip;print(sys.version,pip,pip.__version__)" clearly indicates it is using Python 2.7 (look at the version number in the library path).

By contrast, here's the same thing using a current virtual environment on my development system.

(dojo) airhead-2:tools sholden$ pip -V
pip 1.5.6 from /Users/sholden/dojo/lib/python3.4/site-packages (python 3.4)
(dojo) airhead-2:tools sholden$ python -c "import sys,pip;print(sys.version,pip,pip.__version__)"
3.4.2 (default, Oct 19 2014, 17:50:17)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] <module 'pip' from '/Users/sholden/dojo/lib/python3.4/site-packages/pip/__init__.py'> 1.5.6

You will see that the which command shows that pip and python both come from the same binary directory, and that the versions are matched.

(dojo) airhead-2:tools sholden$ which pip
 /Users/sholden/dojo/bin/pip
(dojo) airhead-2:tools sholden$ which python
/Users/sholden/dojo/bin/python

Virtual environments were invented to keep the dependencies of one project from leaking into other projects. I suggest you think about starting to use them.