说明 该文章写于 2024-8-28
使用 1 2 3 4 5 6 7 8 9 from cx_Freeze import setup, Executablesetup( name="myApp" , version="1.0" , description="a simple app" , executables=[Executable("main.py" )], )
项目根目录下创建一个文件 setup.py 并写入上述内容。
激活虚拟环境
1 .\.venv\Scripts\activate
在虚拟环境中安装这个库
执行命令
经测试,使用了第三方库的可以打包完成,接下来就开始测试pyQt5了
由于gui不需要输出控制台,所以还要修改 setup.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import sysfrom cx_Freeze import setup, Executablebase = None if sys.platform == "win32" : base = "Win32GUI" setup( name="myApp" , version="1.0" , description="a simple app" , executables=[Executable("main.py" , base=base)], )
加上icon,就修改小括号里加参数
1 Executable("main.py" , base=base, icon="./assets/favicon.ico" )
打包pdm项目 fittencode给的答案
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 import sysfrom cx_Freeze import setup, Executablebuild_exe_options = { "packages" : ["project_graph" ], "includes" : ["appdirs" , "PyQt5" ], "include_files" : [], "excludes" : [], "zip_include_packages" : [], "zip_exclude_packages" : [] } base = None if sys.platform == "win32" : base = "Win32GUI" executables = [ Executable( "src/project_graph/__main__.py" , base=base, target_name="project_graph" , icon="src/project_graph/assets/favicon.ico" ) ] setup( name="project_graph" , version="0.1.0" , description="Project Graph" , options={"build_exe" : build_exe_options}, executables=executables )
但实际上不太行,会报错
对于pdm这个项目,需要使用这个包:
https://github.com/frostming/pdm-packer
但实际上用这个专门打包的还是报错了
Author:
Littlefean
License:
Copyright (c) 2019 CC-BY-NC-4.0 LICENSE
Slogan:
仅个人观点,buddy up!