【问题标题】:Im trying to turn a python file into an exe file and its not working我试图将 python 文件转换为 exe 文件,但它不工作
【发布时间】:2020-10-18 15:22:29
【问题描述】:

我尝试使用 pyinstaller main.py --onefile --noconsole 将我的 python 文件变成一个 exe .当我尝试从 dist 打开 exe 时出现错误,所以我使用了--debug=all,它说pyinstaller: error: the following arguments are required: scriptname

我第一次做什么,我不太确定。

【问题讨论】:

  • 听起来您遇到的问题是访问数据文件。如果您删除--noconsole 选项并从命令行运行可执行文件,您将能够看到错误跟踪。有一个answer here,其中包含更多关于数据文件的信息,您可能会觉得有用。
  • 请更新您的问题以包含minimal reproducible example,以便为您提供帮助。

标签: python pygame exe pyinstaller


【解决方案1】:

将python文件转换为exe:

  1. 确保您已安装 pyinstaller 并且是最新的

    pip install pyinstaller

  2. 在 PowerShell 中键入以下内容:

    pyinstaller --onefile -w 'youfilename.py'

文件名应为1.exe 确保在正确的目录中

如果您有更多疑问,请使用此链接:https://www.geeksforgeeks.org/convert-python-script-to-exe-file/

【讨论】:

  • 我确实做到了这一点,我还将我所有的图像和所有内容都放入了 exe 所在的dist 文件夹中,但是当我尝试打开它时,我得到了这个错误Failed to execute script main
  • 尝试 .\pyinstaller --onefile -w 'yourfilename.py' 如果这也不起作用,请给出 pyinstaller 的整个目录地址,然后键入命令
  • 我已经这样做了,但是当我尝试打开 exe 时,我仍然收到错误 Failed to execute main script
  • 您的代码中有任何资产吗?喜欢图像或文件。如果是这样,请确保在 python 代码中提供完整路径。例如“image = 'FULL PATH'” 有时如果 .exe 程序无法找到它,那么它会抛出异常
  • 查看以下链接以了解如何为您的文件添加路径:pyinstaller.readthedocs.io/en/latest/…
猜你喜欢
  • 1970-01-01
  • 2022-06-10
  • 2019-07-13
  • 1970-01-01
  • 2016-11-21
  • 2020-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多