Each Answer to this Q is separated by one/two green lines.
I am currently using PyCharm with Python version 3.4.3 for this particular project.
This PyCharm previously had Python2.7, and I upgraded to 3.4.3.
I am trying to fetch data from an Excel file using Pandas.
Here is my code:
import pandas as pd df = pd.read_excel("File.xls", "Sheet1") print (df)
When I ran this code, I am getting this error.
ImportError: No module named 'xlrd'
I searched Stackoverflow and found some suggestions:
I tried with
pip install xlrd
But, when I did that, the message says
"Requirement already satisfied: xlrd in ./anaconda2/usr/lib/python2.7/site-packages"
I had the same problem. I went to the terminal (Using Linux), and typed
sudo pip3 install xlrd
Then I imported xlrd in python and used the same code:
df = pd.read_excel("File.xlsx", "Sheet1") print (df)
It worked for me!!
You have to download xlrd library because pandas require it.
In Pycharm I downloaded it in File -> Settings -> Project: [PROJECT NAME] -> Project Interpreter
pip install xlrd completed the installation, but that did not resolve the “no named module named xlrd” error.
Copying the xlrd folder to the same folder where the .py programs are stored, resolved this issue.
The problem seems to be because of multiple python versions in the system, where requirement might be satisfied for one and not for the other.
In this case the requirement is satisfied for python2 but not for python3, you need to specify that the download needs to be for python3.
In reference to the answers mentioned above, what worked for me is
python3 -m pip install xlrd
specifying python3 rather than pip3 worked for me.
Click on the Bulb icon right next to the “import xlrd” & click on install package clrd , it will automatically install the package
For me the solution was uninstalling
pip uninstall xlrd, and then installing it again using
pip install xlrd.
If you are in a terminal under Bash or any other semi-advanced shell with tab-completion, try to write
pip followed by
<tab>. If I do it, I see written:
[email protected]:~$ pip pip pip3 pip3.5 pip3.6
As you can see, I can choose to run pip commands under
pip only, but I can choose even newer versions of pip. To know what version is associated to the
pip command (with nothing else) run as usual
pip with the
-V flag. In my case,
pip -V yields:
[email protected]:~$ pip -V pip 9.0.1 from /usr/local/lib/python3.6/dist-packages (python 3.6)
Besides this, if you are developing under PyCharm, you may press
Alt+Enter when the cursor is under the module name which cannot be imported to open a context-sensitive floating menu that will allow you to install the module. (You can also manage the list of installed modules for a specific Python version in the settings menu of PyCharm, under the
Project Interpreter sub-menu.)
I have python 2.7, 3.5 and 3.6 in my linux Mint machine for some reasons.
My spyder uses python 3.5 and I had the same issue. What I have done is
- go to the folder
- Copy the folder
xlrd(Note that to do this action you have right click and open as root)
- Now go to the
/usr/local/lib/python3.6/dist-packagesand paste the folder
It worked for me!!!
This method does not change the default path so that, I can still continue with python 2.7 without any harm(something like
SageMath which I use extensively)
The same happened to me using pycharm, I had installed it with pip, pip3 and anaconda and it still didn’t work.
I manually installed the package from
pycharm-> preferences -> project -> project interpreter -> +
and it worked.
If you are using a virtual environment use “pipenv install xlrd” instead of “pip install xlrd”. That should work.
If you are facing issues in Windows then try the steps below which works for me:
- go to the location
- Open cmd ternimal at this location
pip install xlrd
I copy the modules xlrd and xlrd-1.2.0.dist-info to the project file after
pip/conda install xlrd , and it worked.
The answers listed to date did not work for me. Sadly, the only thing I had to do after running
pip install xlrd, was to restart Visual Studio Code on my Windows 10. I know that it is a different OS than the OP, but hopefully, that helps someone else.
Oh yeah, and I know… restarting should have been my first step.