导入openpyxl模块后运行会报错
Posted mengjinxiang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了导入openpyxl模块后运行会报错相关的知识,希望对你有一定的参考价值。
系统:window10
语言:python
模块:openpyxl
环境:pycharm
说明:openpyxl模块干嘛的?
用来操作excel,这里作者是用来用excel存放测试数据使用。
模块安装:命令pip install openpyxl
E:>pip install openpyxl Collecting openpyxl Downloading https://files.pythonhosted.org/packages/95/8c/83563c60489954e5b80f9e2596b93a68e1ac4e4a730deb1aae632066d704/openpyxl-3.0.3.tar.gz (172kB) 100% |████████████████████████████████| 174kB 9.5kB/s Requirement already satisfied: jdcal in g:helloworldpythonlibsite-packages (from openpyxl) Requirement already satisfied: et_xmlfile in g:helloworldpythonlibsite-packages (from openpyxl) Building wheels for collected packages: openpyxl Running setup.py bdist_wheel for openpyxl ... done Stored in directory: C:UsersMACHENIKEAppDataLocalpipCachewheels585cae768ac132e57e75e645a151f8badac71cc0089e7225dddf76b Successfully built openpyxl Installing collected packages: openpyxl Successfully installed openpyxl-3.0.3 You are using pip version 9.0.1, however version 20.1.1 is available. You should consider upgrading via the ‘python -m pip install --upgrade pip‘ command.
输入操作内容:
import openpyxl
#打开文件,同级不能获取路径
excel_workbook = openpyxl.load_workbook(‘cases.xlsx‘)
print(excel_workbook)
#第二步,获取表单,类似字典操作,已经封装好了
sheet = excel_workbook[‘Sheet1‘]
print(sheet)
运行出现报错:
Traceback (most recent call last): import openpyxl File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxl\\__init__.py", line 6, in <module> from openpyxl.workbook import Workbook File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlworkbook\\__init__.py", line 4, in <module> from .workbook import Workbook File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlworkbookworkbook.py", line 7, in <module> from openpyxl.worksheet.worksheet import Worksheet File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlworksheetworksheet.py", line 24, in <module> from openpyxl.cell import Cell, MergedCell File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlcell\\__init__.py", line 3, in <module> from .cell import Cell, WriteOnlyCell, MergedCell File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlcellcell.py", line 27, in <module> from openpyxl.styles import numbers, is_date_format File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlstyles\\__init__.py", line 4, in <module> from .alignment import Alignment File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlstylesalignment.py", line 5, in <module> from openpyxl.descriptors import Bool, MinMax, Min, Alias, NoneSet File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxldescriptors\\__init__.py", line 3, in <module> from .base import * File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxldescriptorsase.py", line 12, in <module> from openpyxl.utils.datetime import from_ISO8601 File "G:helloWorldpythonPython3.7.7libsite-packagesopenpyxlutilsdatetime.py", line 12, in <module> from jdcal import ( ModuleNotFoundError: No module named ‘jdcal‘
此时打开pycharm设置
点击+号,搜索输入openpyx;
再次运行:
<openpyxl.workbook.workbook.Workbook object at 0x0000025C7A2E0E88> <Worksheet "Sheet1">
完美解决!
以上是关于导入openpyxl模块后运行会报错的主要内容,如果未能解决你的问题,请参考以下文章
python中使用openpyxl模块时报错: File is not a zip file
MySQL数据库导入问题,同样一段指令,有一台电脑能够顺利运行,另外一条就会报错,求解答。代码如下: