【问题标题】:Creating a python executable using py2exe使用 py2exe 创建 python 可执行文件
【发布时间】:2013-08-29 15:34:53
【问题描述】:

我试图创建我的文件 NewExistGUI2.py 的可执行文件,其中 GUI 是使用 wxpython 制作的。该文件依赖于其他两个文件 localsettings.pyTryone.py。我参考了 py2exe 文档,并创建了一个 setup.py 文件:

from distutils.core import setup    
import py2exe

    setup(name = 'python eulexistdb module',
        version = '1.0',
        description = 'Python eXistdb communicator using eulexistdb module',
        author = 'Sarvagya Pant',
        py_modules = ['NewExistGUI2','localsettings','Tryone']
        )

并在命令行中使用

编译程序
python setup.py py2exe

但我没有在 dist 文件夹中创建主程序 NewExistGUI2.py 的任何 .exe 文件。我现在该怎么办?

【问题讨论】:

  • python setup.py py2exe 的输出是什么?它应该告诉你缺少什么,或者为什么它没有为你创建一个 exe。
  • 尝试在 setup.py 中添加:scripts=['NewExistGUI2.py',]。
  • 输出没有显示任何错误信息。它显示字节编译python文件并且没有任何错误。如何告诉 setup.py NewExistGUI2.py 是主文件,localsettings.py、Tryone.py 是附件文件。
  • 添加 scripts=['NewExistGUI2.py'] 也没有用。还尝试将所有文​​件添加到脚本中,但失败了。
  • 那么,我该如何使用 PyInstaller 来创建程序的 EXE 呢??

标签: python py2exe


【解决方案1】:

我会建议你创建一个具有以下结构的模块(ExistGUI):

ExistGUI
\_ __init__.py
|_ localsettings.py
|_ Tryone.py
bin
\_ NewExistGUI2.py

你的 init.py 应该有:

from . import localsettings, Tryone

__version__ = 1.0

您的 setup.py 应该类似于:

from setuptools import setup, find_packages
import ExistGUI
import py2exe

setup(
     name = 'ExistGUI',
     version = ExistGUI.__version__,
     console=['bin/NewExistGUI2.py'],
     description = 'Python eXistdb communicator using eulexistdb module',
     author = 'Sarvagya Pant',
     packages= find_packages(),
     scripts=['NewExistGUI2.py',],
     py_modules = ['localsettings','Tryone'],
     include_package_data=True,
     zip_safe=False,
)

然后运行 ​​python setup.py py2exe。确保在 setup.py 中包含对模块的任何要求。另外,删除之前生成的 dist 目录,以防万一。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 2019-07-14
    • 1970-01-01
    相关资源
    最近更新 更多