将python程式轉換成exe.
一、 先安裝python
2、安裝下載下傳包,一路next。
3、為計算機添加安裝目錄搭到環境變量,如圖把python的安裝目錄添加到pth系統變量中即
可。(D:\\python32 是python的安裝路徑)
<a href="http://s3.51cto.com/wyfs02/M00/53/F9/wKioL1R1RgXzi_v-AATzEpHsWUE474.jpg" target="_blank"></a>
4、測試python安裝是否成功,cmd打開指令行輸入 python 指令,如下圖即成功了
<a href="http://s3.51cto.com/wyfs02/M02/53/F9/wKioL1R1RlCgFvfzAACZb9vZLIs659.jpg" target="_blank"></a>
6、直接解壓安裝到python的安裝目錄即可,C:\Python27\pyinstaller (pyinstaller 就是解壓後的目錄
7、進入到安裝pyinstaller的目錄,建立一個存放py檔案的目錄,在建立的目錄裡放置我們的py程式
8、C:\Python27\PyInstaller-3.1.1
9、 轉換成exe.
在指令行執行:python Makespec.py --console --onefile net\deploy_web.py
也許你會出現以下錯誤,也許不會,不報錯直接第9步
報錯:Configfile is missing or unreadable. Please run Configure.py before building
10、解決方法:
在指令行執行:Configure.py
報錯:Python 2.6+ on Windows support needs pywin32,Please install http://sourceforge.net/projects/pywin32/
如果Python版本太低,則安裝最新版本的 pywin32-217.win32-py2.7.exe,下載下傳位址:http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/
無錯誤時候,繼續執行上 第9步
<a href="http://s3.51cto.com/wyfs02/M00/7E/91/wKioL1cEwrfRkB-oAACJnV_U_i0439.png" target="_blank"></a>
關于-F 參數解釋:
-F, --onefile
create a single file deployment
-D, --onedir
create a single directory deployment (default)
-o DIR, --out=DIR
create the spec file in directory. If not specified, and the current directory is Installer’s root directory, an output subdirectory will be created. Otherwise the current directory is used.
-n NAME, --name=NAME
optional name to assign to the project (from which the spec file name is generated). If omitted, the basename of the (first) script is used.
11、成功後生成一個和py腳本同名的目錄(deploy_web),在dict目錄下就生成一個.exe 程式。
12、執行完.exe程式後生成一個txt檔案,裡面就是想要的資訊、
本文轉自crazy_charles 51CTO部落格,原文連結:http://blog.51cto.com/douya/1582523,如需轉載請自行聯系原作者