如何解决从 python 项目生成可执行文件
我需要从包含多个文件夹和文件的 python 项目生成一个可执行文件。 我尝试使用库 cx_Freeze,但只适用于单个文件项目。
你能告诉我怎么做吗?
解决方法
使用pyinstaller。赶紧跑
pip install pyinstaller
然后用shell打开文件所在的文件夹并运行pyinstaller --onefile FILE.py
其中file是exe运行时应该运行的python文件的名称
在“主”python 文件上运行 pyinstaller 应该可以工作,因为 PyInstaller 会自动导入您使用的任何依赖项(例如其他 python 文件)。
,这是你必须做的:
使用如下指令创建一个 build.py 文件:
import cx_Freeze
executables = [cx_Freeze.Executable("main.py")] # The main script
cx_Freeze.setup(
name="Platform Designer",# The name of the exe
options={"build_exe": {
"packages": ["pygame"],# Packages used inside your exe
"include_files": ["data","instructions.md"],# Files in the exe's directory
"bin_path_includes": ["__custom_modules__"]}},# Files to include inside the exe
executables=executables
)
在命令提示符下运行:
-
python build.py build
构建一个 exe -
python build.py bdist_msi
构建 msi 安装程序
确保在更新 exe 或 msi 时删除 build
和 dist
文件夹。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。