【发布时间】:2016-08-30 14:26:36
【问题描述】:
我运行 pandas 的回溯将我带到:site-packages\pandas\io\excel.py line 58, in get_writer
AttributeError: 'module' object has no attribute '__version__'
我在 PyInstaller 存储库中找到了一个 git 问题的链接 https://github.com/pyinstaller/pyinstaller/issues/1890 找到了我的 openpyxl 版本,手动将其添加到 get_writer 方法中,如下所示:
def get_writer(engine_name):
if engine_name == 'openpyxl':
try:
import openpyxl
#remove when conda update available
openpyxl.__version__ = '2.3.2'
# with version-less openpyxl engine
# make sure we make the intelligent choice for the user
if LooseVersion(openpyxl.__version__) < '2.0.0':
return _writers['openpyxl1']
elif LooseVersion(openpyxl.__version__) < '2.2.0':
return _writers['openpyxl20']
else:
return _writers['openpyxl22']
except ImportError:
# fall through to normal exception handling below
pass
try:
return _writers[engine_name]
except KeyError:
raise ValueError("No Excel writer '%s'" % engine_name)
仍然没有骰子。错误回溯中给出的行号甚至没有改变。然后我将 openpyxl 版本更新为 2.3.5,仍然收到错误。 openpyxl init 文件中有一个 version 变量:
try:
here = os.path.abspath(os.path.dirname(__file__))
src_file = os.path.join(here, ".constants.json")
with open(src_file) as src:
constants = json.load(src)
__author__ = constants['__author__']
__author_email__ = constants["__author_email__"]
__license__ = constants["__license__"]
__maintainer_email__ = constants["__maintainer_email__"]
__url__ = constants["__url__"]
__version__ = constants["__version__"]
except IOError:
# packaged
pass
任何已知或潜在的修复或解决方法?
【问题讨论】:
-
我不认为这与 Pandas 有任何关系,而是你如何安装 openpyxl。唯一受支持的安装方法是使用 pip。
-
@CharlieClark 我通过 pip 和 Anaconda 环境安装了它,两者都是 openpyxl 的 2.3.5 版本规范。我不知道关于 pip。
-
如果 openpyxl 是使用 pip 安装的,那么包括版本在内的元数据将在包中公开。
标签: python pandas openpyxl conda