首页 > 解决方案 > 将excel文件导入python脚本时出现ImportError

问题描述

所以我今天尝试将我的第一个 excel 文件导入到 VIM 中的 python 文档中,但并不顺利。值得注意的是,我不情愿地拥有 3 个版本的 Python,v2.7、3.6 和 3.7,其中 Python 3.6 是使用的版本。

我之前设法在 Vim 上启用了 python 模式,这似乎有效。而且我已经设法安装了熊猫,但 xlrd 似乎不起作用。

我正在尝试将名为 names.xsl 的 excel 文件导入到我的 lab5.py 脚本中,但每次运行 python 脚本时都会出现此错误:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pandas/io/excel.py", line 261, in __init__
    import xlrd
ModuleNotFoundError: No module named 'xlrd'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "lab5.py", line 2, in <module>
    df = pd.read_excel (r'/home/Lab05/names.xsl')
  File "/usr/lib/python3/dist-packages/pandas/util/_decorators.py", line 118, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pandas/io/excel.py", line 230, in read_excel
    io = ExcelFile(io, engine=engine)
  File "/usr/lib/python3/dist-packages/pandas/io/excel.py", line 263, in __init__
    raise ImportError(err_msg)
ImportError: Install xlrd >= 0.9.0 for Excel support

烦人的部分是我已经安装了 xlrd 并且它告诉我要安装它?为什么是这样?到目前为止,这是我的 python 脚本:

  1 import pandas as pd
  2 df = pd.read_excel (r'/home/Lab05/names.xsl')
  3 print (df)

标签: pythonexcelpython-3.xpandasxlrd

解决方案


推荐阅读