ImportError: cannot import name Publisher

匿名 (未验证) 提交于 2019-12-03 08:41:19

问题:

I succesfully created an executable version (Py2exe, Pyinstaller) of my application. When I try to run the app from .exe, I get an error as follows in the log file:

Traceback (most recent call last): File "CreateAS.pyw", line 8, in <module> ImportError: cannot import name Publisher

I am really stuck in this part. Could you help me out?

Thanks

回答1:

I'm guessing that you are using a version of wxPython that is >= 2.8.11.0? If so, the wx.lib.pubsub package has changed. This page describes the changes. There is also a thread on the wxPython mailing list here that talks about this.

To make this all work in my project, I did the following described here which was part of the above mailing list thread. I summarize below:

The much preferable alternative (ie no hacks!) if you can hack it (sorry!) is to use the same messaging protocol as v1, but in latest API, this is called "arg1":

# only in app's startup  module    from wx.lib.pubsub import setuparg1    # in all modules that use pubsub  from wx.lib.pubsub import pub as Publisher 

and replace any occurence of "Publisher()." by "Publisher."

Then in my setup.py script, I had to add the following to the options:

options = {     "py2exe": {"packages": ['wx.lib.pubsub']} } setup(data_files=data_files,       windows=[               {'script': 'btpos.py'],                options=options) 

You should now be able to build an executable using the new version of pubsub, but with the old api. You might also want to check out the new v3 api of pubsub. If your project isn't too big, you can probably get by without changing too much.



回答2:

try like this:

from wx.lib.pubsub import setuparg1 from wx.lib.pubsub import pub as Publisher 

Then: replace any occurence ofPublisher()byPublisher.



回答3:

I was using an example code that used wx.lib.pubsub to study from and came across this problem too.

To fix this issue simply, I just changed the line:

from wx.lib.pubsub import Publisher as pub 

To:

from wx.lib.pubsub import pub 

The accepted answers has links that still make it right, but for simplicity, I've added this solution because the accepted solution was a little confusing.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!