Search code examples
pythonpipxlrd

Python: "ImportError: no module named xlrd" after installing xlrd using pip


After installing xlrd using pip, I am still unable to get it to work in my script. I'm not sure if I am missing something completely obvious - please help!

Currently, entering pip list on command line gives the following:

pip (9.0.1)
setuptools (32.1.0)
wheel (0.29.0)
xlrd (1.0.0)

And entering pip show xlrd gives:

Name: xlrd
Version: 1.0.0
Summary: Library for developers to extract data from Microsoft Excel (tm) spreadsheet files
Home-page: http://www.python-excel.org/
Author: John Machin
Author-email: sjmachin@lexicon.net
License: BSD
Location: /usr/local/lib/python2.7/site-packages
Requires:

Yet, if I go into the python environment (via typing python on command line) and try to import, here's what I get:

Python 2.7.10 (default, Feb  7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlrd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named xlrd

Anyone has encountered this problem before? I also have python 3 installed, and I downloaded xlrd via pip3. Yet import xlrd doesn't work on either versions (2 or 3).


Solution

  • First, you can check if such package actually exists on given directory (simply ls /usr/local/lib/python2.7/site-packages to see if there is __init__.py there).

    If package is on place, you may check environmental variable $PYTHONPATH or just python -c 'import sys; print(sys.path)', which prints all directories where Python takes libraries from.

    If everything is in place and sys.path contains site-packages (if that's not your first package installed via PIP I assume that everything's correct there), it might be problem with permissions. Please check some other stackoverflow question:

    Cannot import a python module that is definitely installed (mechanize)

    If package was installed with root's rw permission only - that would be the case.