有的小伙伴使用Python时发现自己没有xlrd,不要着急,我们一起来解决。
我目前正在使用PyCharm与Python版本3.4.3进行此特定项目。
这个PyCharm以前有Python2.7,我升级到3.4.3.
我正在尝试使用Pandas从Excel文件中获取数据。
代码:
<p style="line-height: 1.75em"><span>import pandas as pd df = pd.read_excel("File.xls", "Sheet1") print (df)<br></span></p>
www#gaodaima.com来源gaodai^.ma#com搞#代!码网搞代码
当我运行此代码时,我收到此错误
<p style="line-height: 1.75em"><span>ImportError: No module named 'xlrd'<br></span></p>
我搜索了Stackoverflow并找到了一些建议:我试过了
<p style="line-height: 1.75em"><span>pip install xlrd<br></span></p>
但是,当我这样做时,消息说
<p style="line-height: 1.75em"><span>"Requirement already satisfied: xlrd in ./anaconda2/usr/lib/<a href="https://www.gaodaima.com/tag/python" title="查看更多关于python的文章" target="_blank">python</a>2.7/site-packages"<br></span></p>
解决:
去终端(使用Linux),然后输入
<p style="line-height: 1.75em"><span>sudo pip3 install xlrd<br></span></p>
然后我在python中导入xlrd并使用相同的代码:
<p style="line-height: 1.75em"><span>df = pd.read_excel("File.xlsx", "Sheet1") print (df)<br></span></p>
学会了的小伙伴可以保存起来,方便下次使用。更多Python学习推荐:云海天Python教程网。
来源:搞代码网:原文地址:https://www.gaodaima.com