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"
Any suggestion?
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
Running the 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.
单击“import xlrd”旁边的灯泡图标,然后单击安装包 clrd ,它将自动安装包
对我来说,溶液卸载xlrd
使用pip uninstall xlrd
,然后再次使用安装它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:
none@vacuum:~$ 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 --version
or -V
flag. In my case, pip -V
yields:
none@vacuum:~$ 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
/usr/local/lib/python2.7/dist-packages
xlrd
(Note that to do this action you have right click and open as root)/usr/local/lib/python3.5/dist-packages
or /usr/local/lib/python3.6/dist-packages
and paste the folder xlrd
over there.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:
%localappdata%
C:\\Users\\<YourSystem>\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts
pip install xlrd
在pip/conda install xlrd
,我将模块 xlrd 和 xlrd-1.2.0.dist-info 复制到项目文件中,并且它起作用了。
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.
I was using VS Code and in my case I have already installed xlrd but the import was not detecting. There were two reason for it:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.