ImportError: Unable to import Publisher name

I have successfully created an executable version (Py2exe, Pyinstaller) of my application. When I try to run the application from .exe, in the log file I get the following error:

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?

thanks

+8
python executable py2exe
source share
3 answers

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

To make all this work in my project, I did here described below which was part of the aforementioned mailing flow. I summarize below:

The most preferred alternative (i.e. no hacks!) If you can hack it (sorry!) Is to use the same messaging protocol as v1, but in the last API it's called "arg1":

 # only in app 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 appearance of "Publisher()." by "Publisher." "Publisher()." by "Publisher."

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

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

Now you can create an executable file using the new pubsub version, but with the old api. You can also check out the new pubsub v3 api. If your project is not too large, you can probably do without too much change.

+12
source share

try like this:

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

Then: Replace any appearance of Publisher() with Publisher.

+4
source share

I used a sample code that used wx.lib.pubsub to learn and came across this problem too.

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

 from wx.lib.pubsub import Publisher as pub 

To:

 from wx.lib.pubsub import pub 

There are links in the accepted answers that still do everything right, but for simplicity I added this solution because the decision made was a bit confusing.

+2
source share

All Articles