【python 问题解决】 ---- ImportError: Missing optional dependency ‘xlrd‘. Install xlrd >= 1.0.0
Python 解决 ---- install missing 1.0 Dependency ImportError
2023-09-14 09:15:07 时间
1. 报错
Traceback (most recent call last):
File "main.py", line 25, in <module>
result = pd.read_excel('./pdfdata1.xlsx')
File "D:\Python\lib\site-packages\pandas\util\_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "D:\Python\lib\site-packages\pandas\io\excel\_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "D:\Python\lib\site-packages\pandas\io\excel\_base.py", line 867, in __init__
self._reader = self._engines[engine](self._io)
File "D:\Python\lib\site-packages\pandas\io\excel\_xlrd.py", line 21, in __init__
import_optional_dependency("xlrd", extra=err_msg)
File "D:\Python\lib\site-packages\pandas\compat\_optional.py", line 110, in import_optional_dependency
raise ImportError(msg) from None
ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.
2. 错误截图
3. 问题描述
使用pandas.read_excel()函数读取xlsx文件里的数据,却报错ImportError: Missing optional dependency ‘xlrd’. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.
4. 解决办法一
执行命令 pip install xlrd 安装相应的安装包
pip install xlrd
5. 解决办法二
执行命令 pip install openpyxl 安装相应的安装包
pip install openpyxl
使用openpyxl代替xlrd,读取文件时记得指定引擎engine=‘openpyxl’
6. 解决问题代码
result = pd.read_excel('./pdfdata1.xlsx', engine='openpyxl')
正常读取,不再报错!
7. 总结
- 使用方案一需要安装对应的版本,因为有的版本xlrd是不能读取xlsx文件;
- 由于我本地有openpyxl安装包,所以使用的是方案二,直接解决了问题;
WXRUI体验二维码
如果文章对你有帮助的话,请打开微信扫一下二维码,点击一下广告,支持一下作者!谢谢!
下载
相关文章
- 【python教程入门学习】PyCharm下载和安装教程(包含配置Python解释器)
- pycharm导入Python_python简单项目
- python 基尼系数_Python计算
- Python概述
- python fileinput_Python之fileinput模块学习「建议收藏」
- Ubuntu16.04系统查看已安装的python版本,及Python2与Python3之间切换
- python解压bz2文件命令,在Python中解压缩.bz2文件
- Python元组_python输出元组
- 【说站】python异常的传递
- Python自动化办公小程序:实现报表自动化和自动发送到目的邮箱
- 【Python问题解决】---- ERROR: Could not install packages due to an OSError: [WinError 2] 系统找不到指定的文件。
- Python学习:dict和set类型的用法
- python上的表白代码_用Python实现表白代码
- python win32api sendmessage_Python win32api.SendMessage方法代码示例[通俗易懂]
- 保姆教程:构建与发布Python包
- 引入业务先验约束的树模型(Python)
- python-Python与PostgreSQL数据库-PostgreSQL数据库的基本知识(二)
- Python 人工智能:11~15
- python生成417条形码(PDF417)详解编程语言
- Linux下安装Python的指南(linux下安装python)
- 使用Python编程连接MySQL数据库(python连mysql)
- Python驱动Oracle数据库(python操作oracle)
- 使用这个 Python 工具分析你的 Web 服务器日志文件
- 使用Python连接SQL Server数据库(python连接sqlserver)
- Python转码问题的解决方法