I have an assignment to read excel data in Python. I have Python 2.7 installed. I tried installing xlrd0.8.0 with the following commands in Windows.
C:\\Pyth
Resolving issue with xlrd import in Python 2.7
open this link https://bootstrap.pypa.io/get-pip.py and save as get-pip.py and copy this file into C:\Python2.7\
C:\Python2.7\python.exe get-pip.py
After this pip is installed in your system now installing xlrd
C:\Python2.7\python.exe -m pip install xlrd
Open python and import xlrd
import xlrd
it will work.
python -m pip install xlrd
For my case I have both python2 and python3 installed, pip install xlrd
default install xlrd into the Python3 library (/usr/local/lib/python3.6/site-packages/xlrd/
. By specifying python2 for pip install solved my problem.
For me, running python in spyder on a mac, it didn't work even after I installed xlrd
using pip, because it was installed to a different location than the one spyder was using. To fix this, I first found where xlrd
was installed to:
$pip install xlrd
Requirement already satisfied: xlrd in /usr/local/lib/python2.7/site-packages
Then copied the xlrd
folder from there into where Spyder could access it:
$cd /Applications/Spyder.app/Contents/Resources/lib/python2.7/
$cp -r /usr/local/lib/python2.7/site-packages/xlrd.
Then updated the module within spyder, but I'm not sure whether this was necessary. Restarting Spyder might have also worked after making those changes.
Please add "C:\Python27\Lib\site-packages\" to your PYTHONPATH in your system variables.
If there is no such SYSTEM VARIABLE, please create it:
I had the same problem, seems like the is better if you export your xlsx to a csv file and then run the following on python
df = pd.read_csv('FileName.csv')
It should work like that. If you're using iPython or even better Jupyter then run df.head()
to check if pandas reads your table properly.
Note, I am using Ubuntu
How to reproduce and fix this error:
Open the python interpreter, try to import xlrt, you get an error:
python
>>> import xlrt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named xlrt
1. Install, or make sure pip is installed:
What is the official "preferred" way to install pip and virtualenv systemwide?
2. Install xlrd
pip install xlrd
Protip: If you feel you have to use sudo pip install ....
to get this to work then you need to stop and learn why this is dangerous. See: What are the risks of running 'sudo pip'?
Workarounds are to install pip using a certain user: pip install --user myuser ...
use your own best judgment here. Make sure the directory your pip is operating in is owned by the user trying to install packages there. Use: chown -R $USER /Library/Python/2.7/site-packages
.
3. Test it on the python interpreter:
python
>>> import xlrd
>>> type(xlrd)
<type 'module'>
>>>
Now it is imported it without a problem, xlrd is a python module.
Troubleshooting:
If your PYTHONPATH is not defined, you should define it:
PYTHONPATH=:/home/el/wherever/where_to_find_modules