终于把打包问题解决了,Python打包方法——Pyinstaller CentOS下踩坑记录
美滋滋,赶紧发给同事试一下
居然报错
Traceback (most recent call last): File "app.py", line 13, inimport d_opt_v0 as mp File "/usr/local/python36/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.__dict__) File "d_opt_v0.py", line 14, in from skimage.measure import label,regionprops File "/usr/local/python36/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.__dict__) File "site-packages/skimage/__init__.py", line 135, in File "/usr/local/python36/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.__dict__) File "site-packages/skimage/data/__init__.py", line 16, in File "/usr/local/python36/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.__dict__) File "site-packages/skimage/data/_binary_blobs.py", line 2, in File "/usr/local/python36/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.__dict__) File "site-packages/skimage/filters/__init__.py", line 3, in File "/usr/local/python36/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.__dict__) File "site-packages/skimage/filters/edges.py", line 17, in File "/usr/local/python36/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.__dict__) File "site-packages/skimage/restoration/__init__.py", line 7, in File "/usr/local/python36/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.__dict__) File "site-packages/skimage/restoration/_denoise.py", line 8, in File "/usr/local/python36/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.__dict__) File "site-packages/pywt/__init__.py", line 16, in File "pywt/_extensions/_pywt.pyx", line 1, in init pywt._extensions._pywt ModuleNotFoundError: No module named 'pywt._extensions._cwt'
莫非环境原因?本地试一下,同样的错误。。。
搜到了这个https://blog.csdn.net/zyc121561/article/details/79562935
需要添加hiddenimport
查一下官方文档
--hidden-import MODULENAME, --hiddenimport MODULENAME
Name an import not visible in the code of the script(s). This option can be used multiple times.
不需要修改package中的配置,直接在打包时候引入参数就可以
pyinstaller -F --hidden-import=pywt --hidden-import=pywt._extensions._cwt app.py
放到服务器上试一下,又报错
ImportError: libxcb.so.1: cannot open shared object file: No such file directory
理论上,应该使用--add-binary,可是实际测下来--add-data也可以
pyinstaller -F --add-binary '/usr/lib64/libxcb.so.1:.' --hidden-import=pywt --hidden-import=pywt._extensions._cwt app.py pyinstaller -F --add-data /usr/lib64/libxcb.so.1:. --hidden-import=pywt --hidden-import=pywt._extensions._cwt app.py
搞定