使用 py2exe 时出现 AssertionError
AssertionError when using py2exe
我是 Python 的新手,我需要一些帮助来解决我收到的错误消息。我试图在 py2exe 的帮助下从 tkinter 脚本制作一个 exe 文件,但每当我尝试 运行 setup.py 脚本时,我总是收到 AssertionError。几天前,我已经在不使用 tkinter 的情况下使用相同的脚本在我的计算机上创建了一个 exe 文件。创建此 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 的帮助下从 tkinter 脚本制作一个 exe 文件,但每当我尝试 运行 setup.py 脚本时,我总是收到 AssertionError。几天前,我已经在不使用 tkinter 的情况下使用相同的脚本在我的计算机上创建了一个 exe 文件。创建此 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。
对我有用。