【问题标题】:using cx_freeze to make an executable python program from multiple python scripts使用 cx_freeze 从多个 python 脚本制作一个可执行的 python 程序
【发布时间】:2021-08-15 01:37:16
【问题描述】:

在使用 pyinstaller 失败后,我开始使用 cx_freeze 使我的项目成为可执行文件, 我正在使用 tkinter 制作 GUI 并且 main.py GUI 正在工作,并且当第二个脚本 GUI 假设初始化它时仅初始化窗口,但没有菜单或 tkinter 的任何依赖项,例如滑块、标签或条目盒子

我的 setup.py 是这样配置的:

import sys
from cx_Freeze import setup, Executable


includefiles = ['Doctor.xlsx']
includes = []
excludes = []
packages = ['tkinter', 'openpyxl']
build_exe_options = {'includes': includes, 'packages': packages, 'excludes': excludes, 'include_files': includefiles}

base = None
if sys.platform == 'win64':
    base = 'Win64GUI'
elif sys.platform == 'win32':
    base = 'Win32GUI'

exe = Executable(
    script="Main.py",
    target_name="AutoDoctor",
    base = base
)
setup(
    name="AutoDoctor",
    version="1.0",
    description="Program to diagnose blood results and generate a matching treatment.",
    options={'build_exe': build_exe_options},
    executables=[exe],
)

在项目中我有多个脚本: Main.py, Diagnosis.py, Database.py 据我了解,Database.py 运行良好,因为 Main.py 脚本使用的是 Database.py 脚本中的数据库。

【问题讨论】:

  • Database.py?那是一个python文件吗?而你只将其命名为数据库?
  • @JoeMo 只是一个我命名为数据库的文件,我使用 openpyxl 将 Excel 文件导入为数据库
  • cxfreeze yourfile.py --target -dir-cx 你试过这个吗?你安装了 cx?
  • @JoeMo 没有尝试这个,我应该在项目目录还是从 python 目录尝试这个?

标签: python tkinter pycharm openpyxl cx-freeze


【解决方案1】:

如果您在 Windows 上,则可以从桌面执行此操作。但如果你想确定的话。转到您的目录并执行以下操作:

打开 cmd 并把这段代码放进去。确保你已经安装了你需要的东西

【讨论】:

  • 我试过了,'cxfreeze' 不被识别为内部或外部命令、可运行程序或批处理文件......即使它安装在项目 venv 脚本中
  • 您将yourfile.py 更改为您的py 文件?对不起这个问题,因为对我来说它有效。
  • 当然,这个操作的问题是cxfreeze无法识别,所以cxfreeze之后写什么py文件也没关系
  • 嗯。我找到了一个指南。对此感到抱歉。不知道你为什么会遇到这个问题。试试这个:pythonprogramming.net/converting-python-scripts-exe-executables
  • 我查看了该指南,它的基本转换 py 到 exe 指南,它与我的问题无关..
【解决方案2】:

原来是我的代码出了问题 在我的代码中,我销毁了主窗口,然后才初始化了第二个功能窗口,所以这只是功能问题的顺序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-24
    • 2021-02-12
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多