記錄使用cx_Freeze打包Python成exe可執行程序


安裝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,效果如下:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM