使用py2exe

时间:2016-12-12 11:20:25

标签: python python-3.4 py2exe distutils

我是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。

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

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

它对我有用。