Python 导入错误:无法导入名称 get_column_letter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36721232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: cannot import name get_column_letter
提问by charsi
I am able to use openpyxl as an import in my code. But when I try to do the following:
我可以在我的代码中使用 openpyxl 作为导入。但是当我尝试执行以下操作时:
from openpyxl.cell import get_column_letter
I get the following error:
我收到以下错误:
ImportError: cannot import name get_column_letter
I am using python 2.7. I have installed it using easy_install. Tried searching for this issue but couldn't find anything related to it.
我正在使用 python 2.7。我已经使用easy_install. 尝试搜索此问题,但找不到与之相关的任何内容。
回答by Abbas
The function get_column_letterhas been relocated in Openpyxl version 2.4 from openpyxl.cellto openpyxl.utils.
该函数get_column_letter已在 Openpyxl 2.4 版中从openpyxl.cell到openpyxl.utils.
The current import is: from openpyxl.utils import get_column_letter
当前的导入是: from openpyxl.utils import get_column_letter
If you want to do not know which version the end-user has, you can use the following code:
如果你想不知道最终用户有哪个版本,你可以使用下面的代码:
try:
from openpyxl.cell import get_column_letter
except ImportError:
from openpyxl.utils import get_column_letter
回答by darla_sud
from openpyxl.utils import get_column_letter
from openpyxl.utils import get_column_letter
This is working for Python3also.
这也适用于Python3。
回答by Jael Woo
I got the same problem and I reinstall the latest openpyxlusing "python setup.py install". Then it works.
我遇到了同样的问题,我使用“python setup.py install”重新安装了最新的 openpyxl。然后它起作用了。
回答by shyed2001
print(openpyxl.cell.get_column_letter(1)) # does not work …
You would rather use
你宁愿使用
print(openpyxl.utils.get_column_letter(1))
回答by Bryce
tl;dr for Python3
tl;dr for Python3
pip3 install Cythonpip3 install pandas
pip3 install Cythonpip3 install pandas
Neither of the other two solutions from Abbas or Jael Woo worked for me for Python3.
来自 Abbas 或 Jael Woo 的另外两个解决方案都不适用于 Python3。
I ended up using apt-get install python3-pandas, but then pip3 install pandasfailed because it said I needed Cython, as it does mention in the Pandas installation docsthat it is an "optional dependency" anyways.
我最终使用了apt-get install python3-pandas,但后来pip3 install pandas失败了,因为它说我需要 Cython,因为它在Pandas 安装文档中确实提到它无论如何都是“可选依赖项”。
That being said, I ran pip3 install Cythonand then ran pip3 install pandas, and it worked.
话虽如此,我跑了pip3 install Cython又跑pip3 install pandas,它奏效了。
Note: Cython and Pandas installation took a while on Ubuntu (unsure of EC2's Ubuntu version) but seemed to be much quicker on Mac 10.11.5
注意:在 Ubuntu 上安装 Cython 和 Pandas 需要一段时间(不确定 EC2 的 Ubuntu 版本),但在 Mac 10.11.5 上似乎要快得多
EDIT: using apt-get to install Pandas yielded errors because apt-get installed an older version of Pandas. Once I installed/upgraded Pandas using pip3, the ImportErrorswere gone.
编辑:使用 apt-get 安装 Pandas 产生错误,因为 apt-get 安装了旧版本的 Pandas。一旦我使用 pip3 安装/升级了 Pandas,ImportErrors就消失了。
Edit: if you care enough to downvote, try adding some constructive criticism to this answer in the form of a comment
编辑:如果您足够关心否决票,请尝试以评论的形式为此答案添加一些建设性的批评

