gpt4 book ai didi

python - 使用py2exe时出现断言错误

转载 作者:太空宇宙 更新时间:2023-11-03 15:52:54 24 4
gpt4 key购买 nike

我对 Python 相当陌生,我需要一些帮助来解决我收到的错误消息。我试图在 py2exe 的帮助下从 tkinter 脚本创建一个 exe 文件,但每当我尝试运行 setup.py 脚本时,我总是收到 AssertionError 。几天前,我已经在计算机上使用相同的脚本创建了一个 exe 文件,而没有使用 tkinter。创建这个exe文件没有问题。我想知道是否由于我最近已经创建了一个exe文件而出现错误消息。

我的 setup.py 脚本看起来正常:

`# setup.py


from distutils.core import setup
import py2exe
setup(console=['MyScript.py'])`

每当我运行它时,我都会收到此错误:

AssertionError: distutils has already been patched by <class 'py2exe.patch_distutils.patch_distutils.<locals>.Distribution'>

整个回溯看起来像这样:

Traceback (most recent call last):
File "C:\Dir\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pycharm\pycharm_setup_runner.py", line 26, in <module>
exec (fh.read(), globals(), locals())
File "<string>", line 6, in <module>
File "C:\Dir\Python3\lib\distutils\core.py", line 134, in setup
ok = dist.parse_command_line()
File "C:\Dir\Python3\lib\distutils\dist.py", line 471, in parse_command_line
args = self._parse_command_opts(parser, args)
File "C:\Dir\Python3\lib\distutils\dist.py", line 527, in _parse_command_opts
cmd_class = self.get_command_class(command)
File "C:\Dir\Python3\lib\distutils\dist.py", line 817, in get_command_class
__import__ (module_name)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pycharm\pycharm_commands\pycharm_test.py", line 4, in <module>
from setuptools.command import test
File "C:\Dir\Python3\lib\site-packages\setuptools\__init__.py", line 14, in <module>
from setuptools.extension import Extension
File "C:\Dir\Python3\lib\site-packages\setuptools\extension.py", line 10, in <module>
from .dist import _get_unpatched
File "C:\Dir\Python3\lib\site-packages\setuptools\dist.py", line 39, in <module>
_Distribution = _get_unpatched(_Distribution)
File "C:\Dir\Python3\lib\site-packages\setuptools\dist.py", line 35, in _get_unpatched
"distutils has already been patched by %r" % cls
AssertionError: distutils has already been patched by <class'py2exe.patch_distutils.patch_distutils.<locals>.Distribution'>

有谁知道这个问题的解决方法吗?我正在Python3.4.1中工作。

非常感谢您的帮助!

最佳答案

在导入 py2exe 之前尝试导入 setuptools。

这对我有用。

关于python - 使用py2exe时出现断言错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41099709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com