2012-11-06 77 views
0

我使用py2exe從我的.py成功創建了一個.exe文件。但是,當我嘗試從exe文件應用程序,我收到此錯誤信息:py2exe導入錯誤

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

我alredy找到了這個網頁:ImportError: cannot import name Publisher但我使用python2.7。 這裏是我的.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 

回答

1

py2exe不包括使用的所有包,就像本例中與pubsub相關的包一樣。使用這告訴py2exe關於相關發佈訂閱包一個setup.py

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