【问题标题】:Converting .py to .exe with Anaconda使用 Anaconda 将 .py 转换为 .exe
【发布时间】:2017-05-20 18:27:42
【问题描述】:

我使用 PyGame 制作了一个 Python 程序,该程序仅适用于 Python 2.7,所以这是我的 Python 版本。 我使用 Anaconda 是因为它更容易安装模块和使用 python,但该站点没有 2.7 的 py2exe 模块。 有没有另一种方法来转换它?或者在 Anaconda 中安装 2.7 的 py2exe 的方法?

【问题讨论】:

  • 您是否在您的 conda 环境中尝试过pip install py2exe
  • 上面写着'RuntimeError: This package requires Python 3.3 or later'
  • 我明白了; py2exe 似乎停止支持 Python 2。

标签: python python-2.7 anaconda exe


【解决方案1】:

如何使用适用于 Windows 的 Anaconda 3(特别是 Anaconda Prompt)创建可执行文件。

1 - 确保 pyinstaller 已安装在您的 anaconda 中

pip 安装 pyinstaller

2 - 移动到你的 python 脚本目录

cd C:\Users....\program.py

3 - 只需输入以下内容:

pyinstaller --onefile program.py

如果一切顺利,在您拥有 script.py 的文件夹中,您将创建许多文件夹,并且您的可执行文件位于文件夹“dist”内。

如果我的解释令人困惑,请转到此处:https://medium.com/dreamcatcher-its-blog/making-an-stand-alone-executable-from-a-python-script-using-pyinstaller-d1df9170e263

【讨论】:

  • pip install pyinstaller 给了我一个 Python 2.7 和 pyinstaller 4.1 的错误。显然 pyinstaller > 4.0 不支持 Python 2.7。我按照stackoverflow.com/questions/63342345/…中的建议用pip install pyinstaller==3.5解决了它
【解决方案2】:

您可以尝试使用 pyinstaller 构建可执行文件,而不是使用 py2exe。

http://www.pyinstaller.org/downloads.html

根据此链接,pyinstaller 也支持 PyGame 包

https://github.com/pyinstaller/pyinstaller/wiki/Supported-Packages

【讨论】:

    【解决方案3】:

    另一种解决方案是Conda Constructor

    Constructor 是一个工具,它允许为 conda 包的集合构建安装程序。它使用用户提供的规范解决所需的包,并捆绑这些包。它目前可以创建 3 种安装程序,最好将其视为捆绑包的交付工具。有 shell 安装程序、MacOS .pkg 安装程序和 Windows .exe 安装程序。其中每一个都将在最终用户的系统上创建一个环境,其中包含您提供的规范以及任何必要的依赖项。这些安装程序类似于 Anaconda 和 Miniconda 安装程序,并且确实使用构造函数来创建这些安装程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      • 2021-05-02
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多