免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3606 | 回复: 0

linux pyinstaller usage [复制链接]

论坛徽章:
0
发表于 2010-01-13 17:52 |显示全部楼层
pyinstaller 类似于windows的py2exe功能。它可以帮你的python程序所依赖的所有东西进行打包,生成一个可执行文件。在编译pyinstaller的时候遇到很多恶心的问题。不过都解决了。下面是安装和使用流程:
编译流程
1.下载pyinstaller,现在的版本是1.3 (1)wget http://pyinstaller.hpcf.upr.edu/source/1.3/pyinstaller_1.3.tar.gz
2.解包进入源码目录 (1)tar -zxvf pyinstaller_1.3.tar.gz (2)cd pyinstaller-1.3/source/linux
3.编译源代码 (1)python Make.py  生成python的 .pyc文件
如无错误,则出现如下提示(只有一行): Now run "make" to build the targets: ../../support/loader/run ../../support/loader/run_d
这里如果出了一个少xx.a文件的warning的话,需要安装一个包[color="#0001FF"]sudo apt-get install python2.5-dev[color="#0001FF"]
(2)make 连接生成linux的 .o 文件 make过程中出现下面error:root@wangyu-desktop:linux # makegcc -pthread  -I/usr/include -I/usr/include/python2.5 -I../common -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -DHAVE_WARNINGS -c getpath.c -o getpath.occ1: error: unrecognized option `-fwrapv'cc1: error: unrecognized option `-fwrapv'make: *** [getpath.o] 错误 1
这里也不知道应该用什么版本gcc来编译,找了半天资料也没找到。之后把Makefile里的-fwrapv改成-wrapv。就可以了
4.生成编译配置文件 (1)python Configure.py  生成config.dat配置文件
运行流程root@wangyu-desktop:b142_beacon_fireboltex_linux # python pyinstaller-1.3/Configure.py I: computing EXE_dependenciesI: Finding TCL/TK...I: could not find TCL/TKI: testing for Zlib...I: ... Zlib availableI: Testing for Unicode support...I: ... Unicode availableI: testing for UPX...[color="#990102"]I: ...UPX availableI: computing PYZ dependencies...
如果提示UPX没有的话。去下面链接下载
http://upx.sourceforge.net/upx-3.04-i386_linux.tar.bz2
下面我有一个hello world程序。
root@wangyu-desktop:b142_beacon_fireboltex_linux # cat main.py if __name__ == "__main__":    print 'hello'
root@wangyu-desktop:b142_beacon_fireboltex_linux # python pyinstaller-1.3/Makespec.py main.py wrote /home/bigfish/work/beacon_smartdownloader_bringup/b142_beacon_fireboltex_linux/main.specnow run Build.py to build the executable
root@wangyu-desktop:b142_beacon_fireboltex_linux # python pyinstaller-1.3/Build.py main.spec checking Analysisbuilding because pyinstaller-1.3/support/useUnicode.py changedrunning Analysis out0.tocAnalyzing: pyinstaller-1.3/support/_mountzlib.pyAnalyzing: pyinstaller-1.3/support/useUnicode.pyAnalyzing: main.pyWarnings written to /home/bigfish/work/beacon_smartdownloader_bringup/b142_beacon_fireboltex_linux/warnmain.txtchecking PYZchecking PKGrebuilding out3.toc because pyinstaller-1.3/support/useUnicode.py changedbuilding PKG out3.pkgchecking ELFEXErebuilding out2.toc because mtimes don't matchbuilding ELFEXE out2.tocchecking COLLECTbuilding out4.toc because /home/bigfish/work/beacon_smartdownloader_bringup/b142_beacon_fireboltex_linux/buildmain/main is more recentbuilding COLLECT out4.toc
之后会生成一个distmain的目录。
root@wangyu-desktop:b142_beacon_fireboltex_linux # ll distmain/总用量 4.7M-rwxr-xr-x 1 root root  22K 2009-07-23 00:52 zlib.so-rwxr-xr-x 1 root root 464K 2009-07-23 00:52 unicodedata.so-rwxr-xr-x 1 root root  25K 2009-07-23 00:52 _struct.so-rwxr-xr-x 1 root root  22K 2009-07-23 00:52 strop.so-rwxr-xr-x 1 root root  25K 2009-07-23 00:52 _multibytecodec.so-rwxr-xr-x 1 root root  29K 2009-07-23 00:52 itertools.so-rwxr-xr-x 1 root root  17K 2009-07-23 00:52 cStringIO.so-rwxr-xr-x 1 root root  93K 2009-07-23 00:52 _codecs_tw.so-rwxr-xr-x 1 root root 117K 2009-07-23 00:52 _codecs_kr.so-rwxr-xr-x 1 root root 219K 2009-07-23 00:52 _codecs_jp.so-rwxr-xr-x 1 root root  16K 2009-07-23 00:52 _codecs_iso2022.so-rwxr-xr-x 1 root root 136K 2009-07-23 00:52 _codecs_hk.so-rwxr-xr-x 1 root root 125K 2009-07-23 00:52 _codecs_cn.so-rwxr-xr-x 1 root root  29K 2009-07-23 00:52 bz2.so-rwxr-xr-x 1 root root  17K 2009-07-23 00:52 binascii.so-rwxr-xr-x 1 root root  32K 2009-07-23 00:52 array.so-rwxr-xr-x 1 root root 9.5K 2009-08-18 09:04 libutil.so.1-rwxr-xr-x 1 root root 110K 2009-08-18 09:04 libpthread.so.0-rwxr-xr-x 1 root root 146K 2009-08-18 09:04 libm.so.6-rwxr-xr-x 1 root root 9.5K 2009-08-18 09:04 libdl.so.2-rwxr-xr-x 1 root root 1.4M 2009-08-18 09:04 libc.so.6-rwxr-xr-x 1 root root 1.7M 2010-01-13 17:51 main
root@wangyu-desktop:b142_beacon_fireboltex_linux # ./distmain/main hello
可以看到执行成功了。

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93255/showart_2147825.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP