PyInstaller2.0 使用

各版本的PyInstaller的使用方式大不相同。

PyInstaller2.0英文手册:

http://www.pyinstaller.org/export/v2.0/project/doc/Manual.pdf?format=raw

在下载的PyInstaller文件中有PDF使用手册。

 

Windwos中使用PyInstaller,需要pywin32

http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/

 

手册要点:

1、假设解压至E:/PyInstaller中,如果在该目录中运行python pyinstaller.py [opts]  your-program.py,会在该目录下生成一个your-program的文件夹,并且在该文件夹下会生成dist、build、spec文件。如果是在其它目录中运行,例如python e:/PyInstaller/pyinstaller.py [opts] your-program.py 会在该目录下生成dist、build、spce文件,即不会生成your-program文件夹。[opts]是可选项。

如果成功生成spec文件之后,运行python pyinstaller.py [opts] your-program.spec。

要做的差不多就是这些,如果有其它的选项需要,可以看“Allowed OPTIONS",如果还是不行,看"Spec Files"的介绍。

 

2、引用数据文件

1)修改你的程序:

basedir = os.path.dirname(__file__)

if getattr(sys, 'frozen', None):

     basedir = sys._MEIPASS

else:

     basedir = os.path.dirname(__file__)

2)收集数据文件

数据的收集是放在spec文件中。

遇到的问题

1、section xx 找不着,在配置文件中的配置无法找到。

2、No module named xx.xx.xx 找不能某定自定义的模块。

3、在Linux下运行pyinstaller.py时,有Python library not found!错误。

(这可能是因为Python是动态编译还是静态编译的问题,或者是多版本Python的原因。)

可参考:

http://www.crifan.com/use_pyinstaller_to_package_python_to_single_executable_exe/

猜你喜欢

转载自zerxd.iteye.com/blog/1903810
今日推荐