【问题标题】:How to compile with py2exe to single file?如何用 py2exe 编译成单个文件?
【发布时间】:2022-02-15 00:48:50
【问题描述】:

我需要将我的 python 代码编译为 .exe 以供用户分发。我正在尝试pyinstaller - 工作正常,但 Win Defender 将生成的 .exe 阻止为病毒。我尝试several things 来避免它,但没有成功。

所以现在我尝试使用 py2exe 实用程序。我管理它像这样运行(这应该是一个文件):

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
    console = ["myApp.py"],
    zipfile = None,
)

编译正常,我什至可以从 dist 文件夹运行它,但是一旦我将 .exe 移动到不同的位置,它就会给我错误

AttributeError: module 'http.client' has no attribute 'HTTPSConnection'. Did you mean: 'HTTPConnection'?

Http 是 myApp 中使用的模块。

这是 dist 文件夹的内容:

【问题讨论】:

    标签: python pyinstaller py2exe


    【解决方案1】:

    您可以使用 auto-py-to-exe 并获得一个 GUI 来完成任务。它允许您制作单个文件。只需使用pip install auto-py-to-exe 安装并使用auto-py-to-exe 命令运行

    【讨论】:

    • 好的,但这只是 pyinstaller 的 GUI,正如我所提到的,pyinstaller 输出被 Win Defender 阻止为病毒。
    猜你喜欢
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 2010-09-11
    • 2012-12-16
    相关资源
    最近更新 更多