Python: "ImportError: no module named xlrd" after installing xlrd using pip
what is python used for
introduction to python
python programming examples
python from scratch
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!
pip list on command line gives the following:
pip (9.0.1) setuptools (32.1.0) wheel (0.29.0) xlrd (1.0.0)
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: email@example.com 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
import xlrd doesn't work on either versions (2 or 3).
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
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.
Welcome to Python.org, Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design Browse a Global Pool of Python Programmers and Find Candidates in Minutes. Find Talent for Short-Term, Recurring, & Full-Time Administrative Assistant Contract Work.
you can try this:
import pip package_name='xlrd' pip.main(['install', package_name])
Uninstall and install xlrd. May be at installing time you would have got some error. This error shows only if xlrd is not installed. Use sudo pip install xlrd to install in python 2.7
Python Tutorial, Take-Away Skills: This course is a great introduction to both fundamental programming concepts and the Python programming language. By the end, you'll be Learn Python Like a Pro. From The Basics All The Way to Creating your own Apps and Games! Join Over 50 Million Students Already Learning Online With Udemy
I solved the issue with upgrading pip and following Bibek Ghimire's answer. It seems that I was using pip version 9 whereas version 18 has been already realized.
Learn Python 2, learnpython.org is a free interactive Python tutorial for people who want to learn Python, fast. Python's convenience has made it the most popular language for machine learning and artificial intelligence. Python's flexibility has allowed Anyscale to make ML/AI scalable from laptops to clusters. Python provides convenience and flexibility for scalable ML/AI by Dean Wampler
Learn Python, The class includes written materials, lecture videos, and lots of code exercises to practice Python coding. These materials are used within Google Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace.
Google's Python Class | Python Education, Learn Programming for Everybody (Getting Started with Python) from University of Michigan. This course aims to teach everyone the basics of programming Python is a programming language. Python can be used on a server to create web applications. Start learning Python now »
Programming for Everybody (Getting Started with Python), Python for Everybody Specialization. Learn to Program and Analyze Data with Python. Develop programs to gather, clean, analyze, and visualize data. Learn Python, a powerful language used by sites like YouTube and Dropbox. Learn the fundamentals of programming to build web apps and manipulate data. Master Python loops to deepen your knowledge.
- What's the result of
- Turns out my python environment didn't have
/usr/local/lib/python2.7/site-packagesas one of its sys.path. For me the situation is a bit trickier since I need different PYTHONPATH for different versions of python, bur for now
sys.path.append('/usr/local/lib/python2.7/site-packages')works as a quick fix. Thanks! :)
- @AnthonyChen If you use virtualenv (that I highly encourage to use), you can set different PYTHONPATH for each virtualenv, as stated here: stackoverflow.com/questions/4757178/… BTW if this fixes your problem you can mark it as proper solution, so other developers who search for same thing will find the answer.
- While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
- Would you know if pip automatically appends paths to python's sys.path? If so perhaps that was what failed during installation. After checking sys.path following the other comment's suggestion I found that my python environment does not contain a path to
/usr/local/lib/python2.7/site-packages, which seems rather unusual to me.