当pandas导入openpyxl模块时,该模块没有属性''uuuversion''

2024-07-03 02:10:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我从运行熊猫的回溯到:
site-packages\pandas\io\excel.py line 58, in get_writer AttributeError: 'module' object has no attribute '__version__'

我在PyInstaller repo中找到了指向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,仍然收到错误消息。openpyxlinit文件中有一个版本变量:

^{pr2}$

任何已知或潜在的修复或解决方法?在


Tags: the方法name版本getmakereturnif
3条回答

编辑没有产生影响,因为进程被编译成这些模块正在运行的exe。将我需要的部分导出到我的Python环境之外,现在这个过程工作得很顺利。在

我将在这个讨论中加入我的解决方法,因为我在使用openpyxl2.4.0时遇到了同样的问题,可能其他一些人也遇到了问题。 我发现要创建一个.exe文件,你必须还原到openpyxl的旧版本。为此:

  1. 打开命令提示符并使用“pip uninstall openpyxl”卸载openpyxl
  2. 使用旧版本“pip install openpyxl==2.3.5”重新安装openpyxl

现在您应该能够使用py2exe、cx_freeze等创建.exe文件

这是我的解决方法:转到你的openpyxl站点包文件夹(对我来说是:C:\Python27\Lib\site packages\openpyxl)。复制中的所有变量。常量.json文件直接放入\uinit\uy文件中,因此它看起来像:

import json
import os
__author__= "See AUTHORS"
__author_email__= "eric.gazoni@gmail.com"
__license__= "MIT/Expat",
__maintainer_email__= "openpyxl-users@googlegroups.com"
__url__= "http://openpyxl.readthedocs.org"
__version__= "2.4.0"
try:
    here = os.path.abspath(os.path.dirname(__file__))

相关问题 更多 >