1. 程式人生 > >將Python的.py文件轉變為可執行文件.exe

將Python的.py文件轉變為可執行文件.exe

顯示錯誤 div ron 錯誤 .exe 執行 head python環境 color

python是個很強大的工具,但我們生成的.py文件在沒有Python環境下運行就需要轉為.exe文件,我使用的是PyInstaller

1、安裝PyInstaller:

pip install PyInstaller

2、事先寫好py程序

3、

cmd下進入解壓出來的目錄,執行如下命令:

python pyinstaller.py [opts] yourprogram.py

主要選項包括:

-F, -onefile 打包成一個exe文件

-D, -onedir 創建一個目錄,包含exe文件,但會依賴很多文件(默認選項)

-c, -console, -nowindowed 使用控制臺,無界面(默認)

-w, -windowed, -noconsole 使用窗口,無控制臺

4、我按照3的方法執行顯示錯誤,提示找不到pyinstaller.py,我在E:\ProgramData\Anaconda3\Scripts文件夾下找到了pyinstaller.exe文件(沒裝Anaconda3的朋友可能會在Python安裝目錄的Scripts中找到)。我的方法是:

在E:\ProgramData\Anaconda3\Scripts文件夾下進入cmd,執行命令:pyinstaller.exe [opts] yourprogram.py

例如:pyinstaller.exe -F E:\Pythonchengxu\test.py

成功後會在E:\ProgramData\Anaconda3\Scripts\dist找到生成的.exe文件

將Python的.py文件轉變為可執行文件.exe