各版本的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/