使用 Pyinstaller 编译程序时, Pywt 没有正确导入_cwt
模块。我验证了_cwt.py
它存在于我的 pywt 根目录中(在路径上的站点包中)并且_cwt.pyd
在pywt\_extensions
目录中。我可以从 Python 成功导入 pywt。下面是一个最小(非)工作示例来说明ImportError
回溯。
程序pywt_test.py
# -*- coding: utf-8 -*-
try:
import sys, traceback
import pywt
print pywt.__version__
except ImportError:
type_, value_, traceback_ = sys.exc_info()
e_msg = traceback.format_exception(type_, value_, traceback_)
with open('pywt_error_log.txt','w') as f:
f.write(''.join(e_msg))
Pyinstaller 规范文件pywt_test.spec
# -*- mode: python -*-
block_cipher = None
a = Analysis(['pywt_test.py'],
pathex=['C:\\Users\\user', 'C:\\Users\\user'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='pywt_test',
debug=False,
strip=False,
upx=False,
console=True)
Pyinstall 编译命令:pyinstaller pywt_test.spec
.
命令运行: pywt_test.exe
内容pywt_error_log.txt
:
Traceback (most recent call last):
File "pywt_test.py", line 10, in <module>
File "c:\users\user\appdata\local\temp\pip-build-3zvqo7\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
File "site-packages\pywt\__init__.py", line 16, in <module>
File "c:\users\user\appdata\local\temp\pip-build-3zvqo7\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 546, in load_module
File "pywt\_extensions\_pywt.pyx", line 1, in init pywt._extensions._pywt (pywt\_extensions\_pywt.c:32588)
ImportError: No module named _cwt
我尝试添加_cwt
到 pathex、hiddenimports 等。没有改变错误。
如何获取_cwt
pywt 包和整个 pywt 包以使用 Pyinstaller 加载?
版本,供参考:
- pywt:0.5.1
- 安装程序:3.2.1
- Python:Windows 7 64 位(Anaconda)上的 2.7.12 64 位