如何解决ModuleNotFoundError:没有名为“openpyxl.cell._writer”的模块?

问题描述 投票:0回答:2

我正在尝试为使用 python POyqt5 创建的 GUI 构建一个 exe 文件。完成该过程后,我尝试启动 UI,但收到以下错误:

Traceback (most recent call last):
  File "main_3.py", line 14, in <module>
    import openpyxl
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module 
  File "openpyxl\___init__.py", line 6, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "openpyxl\workbook\____init__.py", line 4, in <module>
  File "PyInstaller\loader\pyimode2_importers.py", line 499, in exec_module
  File "openpyxl\workbook\workbook.py", line 9, in <module>
  File "PyInstaller\loader\pyimode2_importers.py", line 499, in exec_module
  File "openpyxl\worksheet\_write_only.py", line 13, in <module>
  File "openpyxl\worksheet\_writer.py", line 23, in init openpyxl.worksheet._writer 
ModuleNotFoundError: No module named 'openpyxl.cell._writer'
[13336] Failed to execute script 'main_3' due to unhandled exception!

我已经安装了 openpyxl,并且还将它导入到了我的 python 脚本中。尽管如此,这个错误仍然存在。任何解决此问题的线索将不胜感激。

谢谢!

python pyinstaller openpyxl
2个回答
2
投票

假设您正在使用

.exe
创建
pyinstaller
,请尝试:

pyinstaller YOUR_FILE.py --hidden-import openpyxl.cell._writer

它让

pyinstaller
知道必须导入
openpyxl.cell._writer
。看起来这个模块导入是在 Python 脚本中以“隐藏”方式完成的。因此,它对于
pyinstaller
不可见,必须明确提及。


2
投票

将 openpyxl 降级到版本 3.0.9 也可能有帮助。它对我有用。

pip uninstall openpyxl
pip install openpyxl==3.0.9
© www.soinside.com 2019 - 2024. All rights reserved.