Xlwings模块导致PyInstaller EXE抛出异常

时间:2016-03-10 19:40:39

标签: python python-3.x pyinstaller xlwings

我正在尝试使用pyinstaller冻结一个名为 test.py 的简单Python 3.4脚本。该脚本导入xlwings模块的0.7.0版本(我通过pip安装),然后打印一条消息。

import xlwings
print("Fine!")

如果我删除了xlwings导入,那么pyinstaller test.py会在 dist 文件夹中生成一个EXE(我在Windows 10上),该文件夹会打印出“Fine”消息,然后退出。但是,如果我导入xlwings模块,该命令会生成一个打印此消息的EXE,然后退出(不打印“精细”消息):

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\xlwings\__init__.py", line 20, in <module>
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\xlwings\_xlwindows.py", line 29, in <module>
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\pandas\__init__.py", line 7, in <module>
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 573, in load_module
    module = loader.load_module(fullname)
  File "pandas\tslib.pyx", line 55, in init pandas.tslib (pandas\tslib.c:102924)
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "dateutil\zoneinfo\__init__.py", line 31, in <module>
  File "dateutil\zoneinfo\__init__.py", line 24, in getzoneinfofile
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\OrangeFlash81\\AppData\\Local\\Temp\\_MEI102122\\dateutil\\zoneinfo'
test returned -1

我知道导入cx_Freezedateutil存在问题,此错误消息引用dateutilpyinstaller是否会遇到同样的问题,如果是,我该如何解决?

1 个答案:

答案 0 :(得分:0)

这不完全是一个解决方案,但我决定转而使用XLRD模块,该模块可以完成我需要的所有工作并与pyinstaller完美配合;将xlwings代码更改为使用XLRD并不太困难。