Python:Pandas pd.read_excel 给出 ImportError:安装 xlrd >= 0.9.0 以获得 Excel 支持
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48066517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support
提问by Vineeth Sai
I am trying to read a .xlsx
with pandas, but get the follwing error:
我正在尝试.xlsx
使用熊猫阅读,但出现以下错误:
data = pd.read_excel(low_memory=False, io="DataAnalysis1/temp1.xlsx").fillna(value=0)
Traceback (most recent call last):
File "/Users/Vineeth/PycharmProjects/DataAnalysis1/try1.py", line 9, in <module>
data = pd.read_excel(low_memory=False, io="DataAnalysis1/temp1.xlsx").fillna(value=0)
File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/util/_decorators.py", line 118, in wrapper
return func(*args, **kwargs)
File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/io/excel.py", line 230, in read_excel
io = ExcelFile(io, engine=engine)
File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/io/excel.py", line 263, in __init__
raise ImportError(err_msg)
ImportError: Install xlrd >= 0.9.0 for Excel support
I've also tried
我也试过
data = pd.read_excel("DataAnalysis1/temp1.xlsx", low_memory=False).fillna(value=0)
And I Still get the same error.
我仍然遇到同样的错误。
Background: I'm trying to extract an excel file with multiple worksheets as a dict of data frames.I installed xlrd version 0.9.0 and the latest version(1.1.0) but I still get the same error. Thanks!
背景:我试图提取一个带有多个工作表的 excel 文件作为数据帧的字典。我安装了 xlrd 版本 0.9.0 和最新版本(1.1.0),但我仍然遇到相同的错误。谢谢!
回答by Grr
As @COLDSPEED so eloquently pointed out the error explicitly tells you to install xlrd.
正如@COLDSPEED 如此雄辩地指出错误明确告诉您安装 xlrd。
pip install xlrd
And you will be good to go.
你会很高兴去的。
回答by E. Erfan
Either use:
要么使用:
pip install xlrd
And if you are using conda, use
如果您使用的是 conda,请使用
conda install -c anaconda xlrd
That's it. good luck.
就是这样。祝你好运。
回答by Omkar
I was getting an error
我收到一个错误
"ImportError: Install xlrd >= 1.0.0 for Excel support"
“导入错误:安装 xlrd >= 1.0.0 以获得 Excel 支持”
on Pycharm for below code
在 Pycharm 上获取以下代码
import pandas as pd
df2 = pd.read_excel("data.xlsx")
print(df2.head(3))
print(df2.tail(3))
Solution : pip install xlrd
解决方案 : pip install xlrd
It resolved error after using this.
Also no need to use "import xlrd
"
使用它后它解决了错误。也不需要使用“ import xlrd
”
回答by Minhaj Javed
This works for me: For Python 3
这对我有用:对于 Python 3
pip3 install xlrd --user
pip3 安装 xlrd --user
For Python2
对于 Python2
pip install xlrd --user
pip install xlrd --user
回答by Consuelo de tontos
I don't know if this will be helpful for someone, but I had the same problem.
I wrote pip install xlrd
in the anaconda prompt while in the specific environment and it said it was installed, but when I looked at the installed packages it wasn't there.
What solved the problem was "moving" (I don't know the terminology for it) into the Scripts
folder of the specific environment and do the pip install xlrd
there.
Hope this is useful for someone :D
我不知道这是否对某人有帮助,但我遇到了同样的问题。我pip install xlrd
在特定环境中的 anaconda 提示符中写道,它说它已安装,但是当我查看已安装的软件包时,它并不存在。解决问题的是“移动”(我不知道它的术语)到Scripts
特定环境的文件夹中并在pip install xlrd
那里执行。希望这对某人有用:D
回答by Santosh sanwal
Was getting the error while I was using jupyter.
我在使用 jupyter 时遇到错误。
ModuleNotFoundError: No module named 'xlrd'
...
ImportError: Install xlrd >= 0.9.0 for Excel support
it was resolved for me after using.
使用后为我解决了。
!pip install xlrd
回答by Vivek Sh
I encountered same problem and took 2 hours to figure it out.
我遇到了同样的问题,花了 2 个小时才弄明白。
- pip install xlrd (latest)
- pip install pandas (latest)
- Go to C:\Python27\Lib\site-packages and check for xlrd folder (if there are 2 of them) delete the old version
- open a new terminal and use pandas to read excel. It should work.
- pip install xlrd(最新)
- pip install pandas(最新)
- 转到 C:\Python27\Lib\site-packages 并检查 xlrd 文件夹(如果有 2 个)删除旧版本
- 打开一个新终端并使用pandas读取excel。它应该工作。
回答by C K
Please make sure your python or python3 can see xlrd installation. I had a situation where python3.5 and python3.7 were installed in two different locations. While xlrd was installed with python3.5, I was using python3 (from python3.7 dir) to run my script and got the same error reported above. When I used the correct python (viz. python3.5 dir) to run my script, I was able to read the excel spread sheet without a problem.
请确保您的 python 或 python3 可以看到 xlrd 安装。我遇到过 python3.5 和 python3.7 安装在两个不同位置的情况。虽然 xlrd 与 python3.5 一起安装,但我使用 python3(来自 python3.7 目录)来运行我的脚本并得到了上面报告的相同错误。当我使用正确的 python(即 python3.5 目录)运行我的脚本时,我能够毫无问题地读取 excel 电子表格。
回答by Mark K
Another possibility, is the machine has an older version of xlrd installed separately, and it's not in the "..:\Python27\Scripts.." folder.
另一种可能性是机器单独安装了旧版本的 xlrd,它不在“..:\Python27\Scripts..”文件夹中。
In another word, there are 2 different versions of xlrd in the machine.
换句话说,机器中有 2 个不同版本的 xlrd。
when you check the version below, it reads the one not in the "..:\Python27\Scripts.." folder, no matter how updated you done with pip.
当您检查下面的版本时,它会读取不在“..:\Python27\Scripts..”文件夹中的版本,无论您使用 pip 进行了多少更新。
print xlrd.__version__
Delete the whole redundant sub-folder, and it works. (in addition to xlrd, I had another library encountered the same)
删除整个冗余子文件夹,它可以工作。(除了xlrd,我还有另一个库遇到了同样的情况)
回答by Lennis Herburger
I encountered a similar issue trying to use xlrd in jupyter notebook. I notice you are using a virtual environment and that was the key to my issue as well. I had xlrd installed in my venv, but I had not properly installed a kernel for that virtual environment in my notebook.
我在尝试在 jupyter notebook 中使用 xlrd 时遇到了类似的问题。我注意到您正在使用虚拟环境,这也是我的问题的关键。我在我的 venv 中安装了 xlrd,但我没有在我的笔记本中正确安装该虚拟环境的内核。
To get it to work, I created my virtual environment and activated it.
为了让它工作,我创建了我的虚拟环境并激活了它。
Then... pip install ipykernel
然后... pip install ipykernel
And then... ipython kernel install --user --name=myproject
进而... ipython kernel install --user --name=myproject
Finally, start jupyter notebooks and when you create a new notebook, select the name you created (in this example, 'myproject')
最后,启动 jupyter notebooks,当你创建一个新的 notebook 时,选择你创建的名字(在这个例子中,'myproject')
Hope that helps.
希望有帮助。