安裝Python Python環境:Python 3.6.5 安裝cx_Freeze pip install cx_freeze 創建setup.py 在需要打包的py文件同級目錄創建setup.py文件 執行打包 切換到setup.py目錄 執行 python setup.py build 打包成 ...
安裝Python
Python環境:Python 3.6.5
安裝cx_Freeze
pip install cx_freeze
創建setup.py
在需要打包的py文件同級目錄創建setup.py文件
import sys import os from cx_Freeze import setup, Executable os.environ['TCL_LIBRARY'] = r'D:\Python\Python36\tcl\tcl8.6' os.environ['TK_LIBRARY'] = r'D:\Python\Python36\tcl\tk8.6' base = None if sys.platform == 'win32': base = 'Win32GUI' executables = [ Executable('index.py', targetName='index.exe', base=base) ] include_files = [ r'D:\Python\Python36\DLLs\tcl86t.dll', r'D:\Python\Python36\DLLs\tk86t.dll' ] buildOptions = dict( packages=[], excludes=[], include_files=include_files, ) setup( name='測試1.0', version='1.0', description='測試', options=dict(build_exe=buildOptions), executables=executables )
執行打包
切換到setup.py目錄
執行 python setup.py build
打包成功,打包後的文件如下:
運行index.exe,效果如下: