0

我使用 py2exe 从我的 .py 成功创建了一个 .exe。但是当我尝试从 exe 运行应用程序时,我收到以下错误消息:

Traceback (most recent call last): 
File "StreetSoccer.py", line 13, in <module> 
ImportError: cannot import name Publisher

我已经找到了这个页面:ImportError: cannot import name Publisher but I'm using python2.7. 这是我导入 Publisher 的 .py 行:

from wx.lib.pubsub import Publisher

希望您能够帮助我。


编辑:我做了这些改变:

# from wx.lib.pubsub import Publisher
from wx.lib.pubsub import setupv1
from wx.lib.pubsub import pub
Publisher = pub.Publisher()

现在我收到此错误消息(在 py2exe 之后):

File "StreetSoccer.py", line 14, in <module>
File "wx\lib\pubsub\setupv1.pyc", line 16, in setVersion
File "wx\lib\pubsub\pubsubconf.pyc", line 16, in setVersion
File "wx\lib\pubsub\pubsubconf.pyc", line 70, in setVersion
File "wx\lib\pubsub\pubsubconf.pyc", line 78, in __setupForV1
File "wx\lib\pubsub\pub.pyc", line 24, in <module>
File "wx\lib\pubsub\core\listener.pyc", line 13, in <module>
Import Error: No module named listenerimpl
4

1 回答 1

1

py2exe 不包括您使用的所有包,例如在这种情况下与 pubsub 相关的包。使用 asetup.py告诉 py2exe 相关的 pubsub 包:

setup(
    data_files=data_files,
    windows=[{'script': 'StreetSoccer.py'}],
    options=[{'includes': ["wx.lib.pubsub.*", "wx.lib.pubsub.core.*", 
                           "wx.lib.pubsub.core.kwargs.*"]}]
)

另请参阅:ImportError: cannot import name Publisher

于 2012-11-08T12:24:10.867 回答