cx_Freeze 固化代码的配置文件setup.py




import sys
from cx_Freeze import setup, Executable
# author:908204694@qq.com

base = None
# 判断Windows系统
if sys.platform == 'win32':
    base = 'Win32GUI'


packages = []

for dbmodule in ['win32gui','win32api' ,'win32con' , 'cx_Freeze']:

    try:

        __import__(dbmodule)

    except ImportError:

        pass

    else:
        packages.append(dbmodule)


options = {
                'build_exe': 
                        {
                             'includes': 'atexit'
                             # 依赖的包
                             ,"packages": packages
                             # 额外添加的文件
                             , 'include_files':['image_rc.py']
                            }
                
                }

executables = [
                        Executable(
                                        # 工程的 入口 
                                        'View.py'
                                        , base=base
                                        # 生成 的文件 名字
                                        , targetName = 'DNACheck.exe'
                                        # 生成的EXE的图标
                                       #, icon = "test_32.ico" #图标, 32*32px
                                        )
                    ]

setup(
            # 产品名称
           name='DNACheck',
            # 版本号
            version='1.0',
            # 产品说明
            description='DNACheck',
            options=options,
            executables=executables
      )

















cx_Freeze中打包from openpyxl.drawing.image import Image as excelimage的步骤如下: 1. 安装cx_Freeze库 在命令行中输入以下命令: ``` pip install cx_Freeze ``` 2. 创建setup.py文件 在项目根目录下创建一个名为setup.py文件,内容如下: ``` from cx_Freeze import setup, Executable setup( name="my_program", version="1.0", description="My program description", executables=[Executable("my_program.py")] ) ``` 其中,name和description为你的程序名称和描述,executable列表中的元素为你的程序入口文件名。 3. 修改build_exe_options 在setup.py文件中修改build_exe_options,使cx_Freeze能够打包openpyxl库。修改后的setup.py文件如下: ``` from cx_Freeze import setup, Executable build_exe_options = { "packages": ["openpyxl"], "include_files": [ "path/to/your/excel/files" ] } setup( name="my_program", version="1.0", description="My program description", options={"build_exe": build_exe_options}, executables=[Executable("my_program.py")] ) ``` 其中,packages列表中为你需要打包的所有库,include_files列表中为你需要打包的excel文件路径。 4. 打包程序 在命令行中进入到项目根目录下,输入以下命令: ``` python setup.py build ``` 执行成功后,会在项目根目录下生成一个build文件夹,里面包含了打包好的程序和所需的库文件。 5. 运行程序 找到打包好的程序文件,双击运行即可。如果需要运行时指定excel文件路径,可以在程序中通过命令行参数获取。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值