今天使用pyinstaller打包py脚本,遇到一个问题。
环境:
python: 2.7.11
pyinstaller: 3.2
脚本如下:
-
import sys
-
import redis
-
-
phos = [
-
"..."
-
]
-
-
def sendsms(sms) :
-
-
r = redis.Redis("192.168.125.133")
-
p = r.pipeline()
-
for pho in phos :
-
msg = "%s|%s" %(pho,sms)
-
r.rpush('zabbix_sms_server_queue',msg)
-
p.execute()
-
-
if __name__ == "__main__" :
-
#sms = "%s:%s" %(sys.argv[1] ,sys.argv[2])
-
sms = "%s:%s" %("1.1.1.1" ,"tttttttttt")
-
sendsms(sms)
打包:pyintaller.exe send.py
执行后确出错
-
E:\script\test\dist\sendsms>sendsms.exe
-
Traceback (most recent call last):
-
File "sendsms.py", line 2, in <module>
-
File "c:\python27\lib\site-packages\PyInstaller-3.2-py2.7.egg\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
-
exec(bytecode, module.__dict__)
-
File "build\bdist.win-amd64\egg\redis\__init__.py", line 1, in <module>
-
File "c:\python27\lib\site-packages\PyInstaller-3.2-py2.7.egg\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
-
exec(bytecode, module.__dict__)
-
File "build\bdist.win-amd64\egg\redis\client.py", line 9, in <module>
-
File "c:\python27\lib\site-packages\PyInstaller-3.2-py2.7.egg\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
-
exec(bytecode, module.__dict__)
-
File "build\bdist.win-amd64\egg\redis\_compat.py", line 10, in <module>
-
ImportError: No module named Queue
-
Failed to execute script sendsms
经google,发现pyinstaller 有--hidden-import 选项,打包时加上 --hidden-import=queue 即可解决 。
-
--hidden-import MODULENAME, --hiddenimport MODULENAME
-
Name an import not visible in the code of the
-
script(s). This option can be used multiple times.
网上搜的pyinstaller使用教程:
阅读(6306) | 评论(0) | 转发(0) |