码迷,mamicode.com
首页 > 其他好文 > 详细

导入openpyxl模块后运行会报错

时间:2020-05-24 21:15:40      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:rip   点击   local   director   tar   sid   version   openpyxl   orm   

系统: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:\helloworld\python\lib\site-packages (from openpyxl)
Requirement already satisfied: et_xmlfile in g:\helloworld\python\lib\site-packages (from openpyxl)
Building wheels for collected packages: openpyxl
  Running setup.py bdist_wheel for openpyxl ... done
  Stored in directory: C:\Users\MACHENIKE\AppData\Local\pip\Cache\wheels\b5\85\ca\e768ac132e57e75e645a151f8badac71cc0089e7225dddf76b
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:\helloWorld\python\Python3.7.7\lib\site-packages\openpyxl\__init__.py", line 6, in <module>
    from openpyxl.workbook import Workbook
  File "G:\helloWorld\python\Python3.7.7\lib\site-packages\openpyxl\workbook\__init__.py", line 4, in <module>
    from .workbook import Workbook
  File "G:\helloWorld\python\Python3.7.7\lib\site-packages\openpyxl\workbook\workbook.py", line 7, in <module>
    from openpyxl.worksheet.worksheet import Worksheet
  File "G:\helloWorld\python\Python3.7.7\lib\site-packages\openpyxl\worksheet\worksheet.py", line 24, in <module>
    from openpyxl.cell import Cell, MergedCell
  File "G:\helloWorld\python\Python3.7.7\lib\site-packages\openpyxl\cell\__init__.py", line 3, in <module>
    from .cell import Cell, WriteOnlyCell, MergedCell
  File "G:\helloWorld\python\Python3.7.7\lib\site-packages\openpyxl\cell\cell.py", line 27, in <module>
    from openpyxl.styles import numbers, is_date_format
  File "G:\helloWorld\python\Python3.7.7\lib\site-packages\openpyxl\styles\__init__.py", line 4, in <module>
    from .alignment import Alignment
  File "G:\helloWorld\python\Python3.7.7\lib\site-packages\openpyxl\styles\alignment.py", line 5, in <module>
    from openpyxl.descriptors import Bool, MinMax, Min, Alias, NoneSet
  File "G:\helloWorld\python\Python3.7.7\lib\site-packages\openpyxl\descriptors\__init__.py", line 3, in <module>
    from .base import *
  File "G:\helloWorld\python\Python3.7.7\lib\site-packages\openpyxl\descriptors\base.py", line 12, in <module>
    from openpyxl.utils.datetime import from_ISO8601
  File "G:\helloWorld\python\Python3.7.7\lib\site-packages\openpyxl\utils\datetime.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模块后运行会报错

标签:rip   点击   local   director   tar   sid   version   openpyxl   orm   

原文地址:https://www.cnblogs.com/mengjinxiang/p/12952464.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!