• 记录使用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:PythonPython36	cl	cl8.6'
    os.environ['TK_LIBRARY'] = r'D:PythonPython36	cl	k8.6'
    
    base = None
    if sys.platform == 'win32':
        base = 'Win32GUI'
    
    executables = [
        Executable('index.py', targetName='index.exe', base=base)
    ]
    
    include_files = [
        r'D:PythonPython36DLLs	cl86t.dll',
        r'D:PythonPython36DLLs	k86t.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,效果如下:

  • 相关阅读:
    HTML课堂笔记
    pycrul使用
    计算机网络概述
    重温冒泡排序
    初识MySQL
    宝塔Linux面板安装教程
    运维和shell
    nginx学习总结
    docker学习汇总
    linux 安装redis 完整步骤
  • 原文地址:https://www.cnblogs.com/doocool/p/9119578.html
Copyright © 2020-2023  润新知