您的位置:首页 > 编程语言 > Python开发

Python错误:ImportError: cannot import name get_column_letter 解决办法

2018-06-05 09:07 627 查看

昨天刚遇到了因为python版本更新而遇到的错误,今天一大早又遇到了一次......

同样也是按照书《Python编程快速上手》P221页上的代码做练习,但是却遇到了如下的错误:
import openpyxl
from openpyxl.cell import get_column_letter,column_index_from_letter
wb = openpyxl.load_workbook('example.xlsx')
sheet = wb.get_sheet_by_name('Sheet1')
get_column_letter(100)
D:\>python test.py
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    from openpyxl.cell import get_column_letter,column_index_from_letter
ImportError: cannot import name 'get_column_letter'
这个错误的意思就是导入 get_column_letter方法失败,于是Google了一下发现,get_column_letter方法已经在Openpyxl 的2.4版本中重写了,如今想要用此方法需要从openpyxl.utils中导入,而非从openpyxl.cell。因此正确的导入方式应该为:
from openpyxl.utils import get_column_letter
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐