Chinaunix首页 | 论坛 | 博客
  • 博客访问: 279547
  • 博文数量: 73
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 452
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-22 17:07
个人简介

心态决定命运

文章分类

全部博文(73)

文章存档

2017年(21)

2016年(27)

2015年(21)

2014年(4)

我的朋友

分类: 系统运维

2016-10-12 09:57:18

    
   今天使用pyinstaller打包py脚本,遇到一个问题。
   环境:
          python:  2.7.11 
          pyinstaller:  3.2
    脚本如下:
  

点击(此处)折叠或打开

  1. import sys
  2. import redis

  3. phos = [
  4.     "..."
  5. ]

  6. def sendsms(sms) :

  7.     r = redis.Redis("192.168.125.133")
  8.     p = r.pipeline()
  9.     for pho in phos :
  10.         msg = "%s|%s" %(pho,sms)
  11.         r.rpush('zabbix_sms_server_queue',msg)
  12.     p.execute()
  13.     
  14. if __name__ == "__main__" :
  15.     #sms = "%s:%s" %(sys.argv[1] ,sys.argv[2])
  16.     sms = "%s:%s" %("1.1.1.1" ,"tttttttttt")
  17.     sendsms(sms)

 打包:pyintaller.exe send.py 
  执行后确出错
 

点击(此处)折叠或打开

  1. E:\script\test\dist\sendsms>sendsms.exe
  2. Traceback (most recent call last):
  3.   File "sendsms.py", line 2, in <module>
  4.   File "c:\python27\lib\site-packages\PyInstaller-3.2-py2.7.egg\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
  5.     exec(bytecode, module.__dict__)
  6.   File "build\bdist.win-amd64\egg\redis\__init__.py", line 1, in <module>
  7.   File "c:\python27\lib\site-packages\PyInstaller-3.2-py2.7.egg\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
  8.     exec(bytecode, module.__dict__)
  9.   File "build\bdist.win-amd64\egg\redis\client.py", line 9, in <module>
  10.   File "c:\python27\lib\site-packages\PyInstaller-3.2-py2.7.egg\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
  11.     exec(bytecode, module.__dict__)
  12.   File "build\bdist.win-amd64\egg\redis\_compat.py", line 10, in <module>
  13. ImportError: No module named Queue
  14. Failed to execute script sendsms
  
经google,发现pyinstaller 有--hidden-import 选项,打包时加上 --hidden-import=queue 即可解决 。

点击(此处)折叠或打开

  1. --hidden-import MODULENAME, --hiddenimport MODULENAME
  2.                         Name an import not visible in the code of the
  3.                         script(s). This option can be used multiple times.

网上搜的pyinstaller使用教程:



   
阅读(6231) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~