本文實例講述了Python使用cx_Freeze庫生成msi格式安裝文件的方法。分享給大家供大家參考,具體如下:
①.需要在目錄下面創(chuàng)建一個文件 。setup.py
②.寫入代碼:
import sysfrom cx_Freeze import setup, Executableimport osos.environ['TCL_LIBRARY'] = r'C:/Python36-32/tcl/tcl8.6'os.environ['TK_LIBRARY'] = r'C:/Python36-32/tcl/tk8.6'include_files=[ r'C:/Python36-32/DLLs/tcl86t.dll', r'C:/Python36-32/DLLs/tk86t.dll']# Dependencies are automatically detected, but it might need fine tuning.build_exe_options = {"packages": ["os"], "excludes": ["tkinter"],"include_files":include_files}# GUI applications require a different base on Windows (the default is for a# console application).base = Noneif sys.platform == "win32": base = "Win32GUI"setup(name="video1",#打完包后取的名字 version="2.1",#版本 description="aaaaa",#描述 options={"build_exe": build_exe_options}, executables=[Executable("video.py", base=base)])
③.命令:
python setup.py bdist_msi
生成安裝包以及直接運行的exe文件
python setup.py build
生成exe可執(zhí)行程序
注:此處使用的cx_Freeze
庫可使用pip
命令安裝:
pip install cx_Freeze
此外,若使用Python2.7環(huán)境下安裝時提示Python error: Microsoft Visual C++ 9.0 is required ,則需要安裝一個Micorsoft Visual C++ Compiler for Python 2.7 的包,即可解決問題。
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
新聞熱點
疑難解答