2017-04-07 32 views
1

我有一個Python腳本,我想編譯成單個可執行文件,我已經讀過PyInstaller是最好的選擇,但不幸的是CX_Freeze是我發現的唯一編譯器與Python 3.6一起工作。在CX_Freeze中創建單個的Python 3.6腳本

有沒有辦法用CX_Freeze做到這一點?

回答

2

首先你必須有cx_freeze 5.0.1,因爲它支持python 3.6。

然後,它就像任何3.X版本。 將這個代碼在setup.py文件並替換:

"prog.py" 

與主腳本的名字。

保重,如果你會去控制檯應該

if sys.platform == "win32": 
    base = "console" 

這裏不forgit是代碼:

import sys 
from cx_Freeze import setup, Executable 

# Dependencies are automatically detected, but it might need fine tuning. 
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]} 

# GUI applications require a different base on Windows (the default is for a 
# console application). 
base = None 
if sys.platform == "win32": 
    base = "Win32GUI" 


setup( name = "my prog", 
    version = "1.0", 
    description = "My application!", 
    options = {"build_exe": build_exe_options}, 
    executables = [Executable("prog.py", base = base)]) 

打開命令prompot寫:

cd your directory path 
python setup.py build 
+0

我按照這個步驟,但我得到了下面的錯誤,當通過cmd運行我的exe文件時 '導入錯誤:缺少必需的依賴[ 'numpy的']' 但是當我在我的空閒導入numpy的,它工作正常 '>>>進口numpy' ''>>> – pyd