系统: Ubuntu 14.04.5 LTS
pyinstaller: 3.3.1
gevent: 1.3.5
将python脚本通过pyinstaller编译成可执行文件后,运行报错:
Traceback (most recent call last):
File "cloud_unique.py", line 5, in <module>
import gevent
File "/home/cft/.pyenv/versions/3.5.1/envs/env_3.5.1/lib/python3.5/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "gevent/__init__.py", line 87, in <module>
File "/home/cft/.pyenv/versions/3.5.1/envs/env_3.5.1/lib/python3.5/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "gevent/_hub_local.py", line 101, in <module>
File "gevent/_util.py", line 105, in import_c_accel
File "importlib/__init__.py", line 126, in import_module
ImportError: No module named 'gevent.__hub_local'
[6366] Failed to execute script cloud_unique
解决办法:
pyinstaller 编译时加入 - -hidden-import参数,导入所有找不到的模块
可以写到脚本里:
#!/bin/sh
pyinstaller \
-F cloud_unique.py \
--hidden-import gevent.__hub_local \
--hidden-import gevent.__greenlet_primitives \
--hidden-import gevent.__waiter \
--hidden-import gevent.__hub_primitives \
--hidden-import gevent._greenlet \
--hidden-import gevent.__ident \
--hidden-import gevent.time \
--hidden-import gevent.__semaphore \
--hidden-import gevent._local \
--hidden-import gevent._event \
--hidden-import gevent._queue \
--hidden-import gevent.__imap \
--hidden-import gevent.libuv \
--hidden-import gevent.libuv.loop \
--hidden-import gevent.libev \
--hidden-import gevent.libev.corecffi \
--clean