pandas 启动python脚本时出现panda问题

rm5edbpk  于 2023-01-07  发布在  Python
关注(0)|答案(1)|浏览(252)

我正在使用Jupyter Notebook从xlsx文件创建一个图表。代码工作正常,图表在Jupyter上正确显示,但当我尝试从CLI启动脚本时,我得到了这个结果:
λ PythonUntitled.py

Traceback (most recent call last):<br/> File "Untitled.py", line 25, in <module><br/> 
 df = pd.read_excel(workbook)<br/> File
 "C:\Python\lib\site-packages\pandas\util\_decorators.py", line 299, in
 wrapper<br/>   return func(*args, **kwargs)<br/> File
 "C:\Python\lib\site-packages\pandas\io\excel\_base.py", line 336, in
 read_excel<br/>   io = ExcelFile(io, storage_options=storage_options,
 engine=engine)<br/> File
 "C:\Python\lib\site-packages\pandas\io\excel\_base.py", line 1131, in
 __init__<br/>   self._reader = self._engines[engine](self._io, storage_options=storage_options)<br/> File
"C:\Python\lib\site-packages\pandas\io\excel\_xlrd.py", line 24, in
 __init__<br/>   import_optional_dependency("xlrd", extra=err_msg)<br/> File "C:\Python\lib\site-packages\pandas\compat\_optional.py", line
 109, in import_optional_dependency   raise ImportError(msg) from
 None<br/> ImportError: Missing optional dependency 'xlrd'. Install
 xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.

代码如下:

import pandas as pd
import matplotlib.pyplot as plt

workbook = "sample_scores.xlsx"

df = pd.read_excel(workbook)
print(df.head())

values = df[['Name','Test 1']]
print (values)

ax = values.plot.bar(x='Name', y='Test 1')
plt.show()

我安装了Pandas和matplotlib包,也验证了Python路径,一切都设置正确,但似乎我错过了什么?

相关问题