[英]Pyinstaller ImportError on pywt `_ctw` module
Pywt is not importing _cwt
module correctly when the program is compiled with Pyinstaller. 当使用Pyinstaller编译程序时,Pywt没有正确导入
_cwt
模块。 I verified that _cwt.py
is present in my pywt root (in site-packages on the path) and _cwt.pyd
is in the pywt\\_extensions
dir. 我确认
_cwt.py
存在于我的pywt根目录中(在路径中的site-packages中), _cwt.pyd
存在于pywt\\_extensions
目录中。 I can successfully import pywt from Python. 我可以从Python成功导入pywt。 Below is a minimum (non) working example to illustrate the
ImportError
traceback. 下面是一个最小(非)工作示例来说明
ImportError
回溯。
Program pywt_test.py
编程
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 spec file pywt_test.spec
Pyinstaller spec文件
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 compile command: pyinstaller pywt_test.spec
. Pyinstall编译命令:
pyinstaller pywt_test.spec
。
Command ran: pywt_test.exe
命令运行:
pywt_test.exe
Contents of pywt_error_log.txt
: 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
I tried adding _cwt
to the pathex, hiddenimports, etc. None change the error. 我尝试将
_cwt
添加到pathex,hiddenimports等。无更改错误。
How can I get _cwt
, and the entire pywt package, to load with Pyinstaller? 我怎样才能获得
_cwt
,整个pywt包,与Pyinstaller加载?
Versions, for reference: 版本,供参考:
Just add it to the hidden imports: 只需将其添加到隐藏的导入:
...
hiddenimports=['pywt._extensions._cwt'],
...
As wedesoft mentioned, adding hidden imports works. 正如wedesoft所说,添加隐藏导入是有效的。 To avoid such errors in the future you might add a file
为了避免将来出现此类错误,您可以添加文件
'\\PyInstaller\\hooks\\hook-pywt.py'
'\\ PyInstaller \\钩\\ hook-pywt.py'
with the string: 用字符串:
hiddenimports=['pywt._extensions._cwt']
I simply took an existing file like '\\PyInstaller\\hooks\\hook-patsy.py', changed the hiddenimports line to the one above and saved as hook-pywt.py. 我只是采用了像'\\ PyInstaller \\ hooks \\ hook-patsy.py'这样的现有文件,将hiddenimports行更改为上面的一行并保存为hook-pywt.py。 That should work until you update your PyInstaller.
这应该工作,直到你更新你的PyInstaller。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.