wx.lib.pubsub import Publisher

1,090 views
Skip to first unread message

marc

unread,
Feb 7, 2012, 7:12:55 PM2/7/12
to PyInstaller
Hi all;

I can see this has been discussed before in previous emails, but after
reading them, I still cannot resolve this issue.
I am trying to use pyinstaller to build a Windows executable - where
code makes use of :

wx.lib.pubsub import Publisher

... allowing the model to notify the controller that a change has
occurred.

However, when the executable is run, I get a "ImportError: cannot
import name Publisher" error.
I've tried using all the different imports mentioned on various
threads, most work from Python, but fail to import once run from a
Windows executable built with pyinstaller

Could someone please let me know - currently, what's the best work
around for this issue? I'd really like to get this resolved.

Many thanks for your help,
Marc

Daniel Hyams

unread,
Jun 21, 2012, 3:05:17 PM6/21/12
to pyins...@googlegroups.com
While I'm not proud of this (it's a complete hack), the following seems to work for me.  This is with the pubsub included with wxpython 2.8.11 and later, and you must import in your application like this:

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

I can only verify that this works with the arg1 protocol; it probably will with kwargs as well, but I have not verified.

Anyway, here are the two hooks:

------------------------- cut here  ----
import os
import sys

def hook(mod):
   pth = str(mod.__path__[0])
   if os.path.isdir(pth):
      # if the user imported setuparg1, this is detected by the hook-wx.lib.pubsub.setuparg1.py hook.  That
      # hook sets sys.wxpubsub to "arg1", and we set the appropriate path here.
      protocol = getattr(sys,'wxpubsub','kwargs')
      print "wx.lib.pubsub: Adding %s protocol path"%protocol
      mod.__path__.append(os.path.normpath(os.path.join(pth, protocol)))
     
   return mod
------------------------- cut here  ----


------------------------- cut here  ----
import os
import sys

# if the user imports setuparg1, we just set an attribute in sys that allows us to later find out
# about this.
sys.wxpubsub = "arg1"

------------------------- cut here  ---- 

I told you it was a hack! :O  Maybe the pyinstaller folks who know what they are doing can look at this and determine the correct solution.


On Thu, Jun 21, 2012 at 2:48 PM, Tom <tijeri...@gmail.com> wrote:
Was this ever resolved, I'm having trouble as well. My google-fu has failed me the last couple days. I know its something simple I don't really see anything in the last 6-8 months but I still cant get it to work.

I'm using:
XP Pro SP3
Python V 2.7.3
wx.version returns '2.8.12.1 (msw-ansi)'
I have tried both stable pyinstaller and development one from yesterday (possible version: 2145d84)

When I switched from importing Publisher to 

I've even tried including this hook below:
import os

def hook(mod):
    pth = str(mod.__path__[0])
    if os.path.isdir(pth):
        mod.__path__.append(os.path.normpath(os.path.join(pth, 'kwargs')))
    return mod

After changing the publisher import:
from wx.lib.pubsub import setupkwargs
from wx.lib.pubsub import setuparg1
from wx.lib.pubsub import pub as Publisher
(I have tried every combination of the first two, with both, without  one or the other, and with only import Publisher..)
With one or the other I seem to get:

C:\Documents and Settings\Tom>"C:\Documents and Settings\Tom\Desktop\PyPackagers
\pyinstaller-pyinstaller-2145d84\dist\startme.exe"
Traceback (most recent call last):
  File "<string>", line 7, in <module>
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-2145d84\Py
Installer\loader\iu.py", line 431, in importHook
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-2145d84\Py
Installer\loader\iu.py", line 480, in doimport
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-2145d84\bu
ild\pyi.win32\startme\out00-PYZ.pyz\wx.lib.pubsub.pub", line 24, in <module>
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-2145d84\Py
Installer\loader\iu.py", line 386, in importHook
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-2145d84\Py
Installer\loader\iu.py", line 480, in doimport
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-2145d84\bu
ild\pyi.win32\startme\out00-PYZ.pyz\wx.lib.pubsub.core.listener", line 13, in <m
odule>
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-2145d84\Py
Installer\loader\iu.py", line 409, in importHook
ImportError: No module named listenerimpl

--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pyinstaller/-/9aFhWy6-PcoJ.

To post to this group, send email to pyins...@googlegroups.com.
To unsubscribe from this group, send email to pyinstaller...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyinstaller?hl=en.



--
Daniel Hyams
dhy...@gmail.com

Tom Tijerina

unread,
Jun 21, 2012, 3:31:28 PM6/21/12
to pyins...@googlegroups.com
I very much appreciate the very quick reply, I tried using what you have and it still didn't work and gave me the same error. I'm assuming I've done something wrong.

My 'startme.spec' file is below
-----------------------------------------
# -*- mode: python -*-
a = Analysis(['C:\\Documents and Settings\\Tom\\Desktop\\ToPy v0.001\\startme.py', 
'C:\\Documents and Settings\\Tom\\Desktop\\ToPy v0.001\\irep.py', 'C:\\Documents and 
Settings\\Tom\\Desktop\\ToPy v0.001\\webpro.py'],
             pathex=['C:\\DOCUME~1\\Tom\\Desktop\\PYINST~1'],
             hiddenimports=['wx.lib.pubsub.core', 'wx.lib.pubsub.setuparg1'],
             hookspath='C:\\Documents and 
Settings\\Tom\\Desktop\\pyinstaller-pyinstaller-2145d84\\newhooks\\')
pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name=os.path.join('dist', 'startme.exe'),
          debug=False,
          strip=None,
          upx=True,
          console=True )
-------------------------------------------------


and the command im running (as startme.spec is in the same folder) is simply
----------------------------
python pyinstaller.py startme.spec
-----------------------------

Am I missing something? I've got that sneaky something simple is missing feeling. I keep trying the same few things over and over again and all its doing is  making me realize first hand the definition of insanity. I don't really know or understand wx or pyinstaller enough to know where to even really start. I'm still just learning python. 

Thanks again for your help.

Daniel Hyams

unread,
Jun 21, 2012, 3:58:04 PM6/21/12
to pyins...@googlegroups.com
This is probably the blind leading the blind here.

To me, your Analysis call is a little strange.  Mine looks like this:

   a = Analysis([catpath(HOMEPATH,'support','_mountzlib.py'), 
              catpath(HOMEPATH,'support','useUnicode.py'),
              catpath('..','..',srcdir,'src','main.py')],
              pathex=[srcpath])

where "catpath" is just a little function that I wrote to concatenate multiple strings into one path.  Note that I only have one of my own py files in there, and that's it.  No hiddenimports, and no hookspath; I put my custom hooks just alongside pyinstallers; I'm not sure if that makes a difference or not.

Also, are you seeing a print statement during the build that says "wx.lib.pubsub: adding arg1 protocol path"?  If not, then the hooks that I gave you are not getting called.
--
Daniel Hyams
dhy...@gmail.com

Daniel Hyams

unread,
Jun 21, 2012, 4:02:50 PM6/21/12
to pyins...@googlegroups.com
Also, are you trying to use the arg1 protocol or the kwargs protocol in your application?
--
Daniel Hyams
dhy...@gmail.com

Tom Tijerina

unread,
Jun 21, 2012, 4:28:09 PM6/21/12
to pyins...@googlegroups.com
Right after analizing my files I get:
9296 INFO: Hidden import 'wx.lib.pubsub.core' has been found otherwise
9296 INFO: Hidden import 'wx.lib.pubsub.setuparg1' has been found otherwise
9296 INFO: Hidden import 'encodings' has been found otherwise
9296 INFO: Looking for run-time hooks


So I think they are being loaded without requiring it. I tried to edit my file and hosed it so I reran the pyinstaller from the command line with no options. On the bright side I got a different error, I think I'm slowly making progress. :) Now it says I'm missing mechanize. However that is in include from the second file.

This was after moving your files to the hooks directory, I think that did the trick as far as this little hickup goes. Now I need to resolve that one, Hopefully I'll have some time later on. 

Thanks so much for your help! If you are the blind leader, you have at least traveled the road enough times to remember the path :)

Sebastian Hilbert

unread,
Jun 21, 2012, 4:34:42 PM6/21/12
to pyins...@googlegroups.com
On Thursday, June 21, 2012 04:28:09 PM Tom Tijerina wrote:

> Thanks so much for your help! If you are the blind leader, you have at
> least traveled the road enough times to remember the path :)
>

Look at this ticket.

http://www.pyinstaller.org/ticket/312

We have travelled that path as well but rewrote our code to get rid of pubsub.

Once wxpython 3.0 will be released we might look at it again.

Sebastian Hilbert
GNUmed team

Tom Tijerina

unread,
Jun 21, 2012, 4:36:34 PM6/21/12
to pyins...@googlegroups.com
What are you using instead of wx, if I may ask.

Martin Zibricky

unread,
Jun 21, 2012, 5:16:09 PM6/21/12
to pyins...@googlegroups.com
Tom Tijerina píše v Čt 21. 06. 2012 v 16:28 -0400:
>
> Thanks so much for your help! If you are the blind leader, you have at
> least traveled the road enough times to remember the path :)

Could anyone please summarize how should be the proper fix in
PyInstaller?

Daniel Hyams

unread,
Jun 21, 2012, 6:40:23 PM6/21/12
to pyins...@googlegroups.com
I think that the fix that I have a couple of posts up (a modification to wx.lib.pubsub.core hook, and the addition of a "setuparg1" hook) works.  However, it is a horrible kludge, because it sets a variable in the sys module...in effect setting a global flag if the importing of setuparg1 is done at any point.  I thought that there might be a better way in pyinstaller of recording that the setuparg1 module had been imported.

basically the procedure is:
  1) watch for the import wx.lib.pubsub.setuparg1, setting a flag if it is.
  2) when wx.lib.pubsub.core is later imported, add the appropriate path (either arg1 or kwargs) depending on the flag above.

If I get some time (hard to come by right now), I will add test cases to pyinstaller and test this out on toy cases.  I know that my application is working just fine using wxpython's pubsub, but my fear is that I've forgotten some other tweak that I made, because it has been a while since I did it.



--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To post to this group, send email to pyins...@googlegroups.com.
To unsubscribe from this group, send email to pyinstaller...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyinstaller?hl=en.




--
Daniel Hyams
dhy...@gmail.com

Tom Tijerina

unread,
Jun 21, 2012, 7:35:55 PM6/21/12
to pyins...@googlegroups.com
Sorry I'm at work now and its taken me awhile to get some spare time. I literally just added his files from above with my other hook files and then ran from command:
python pyinstaller.py "path/to/files/1" "path/to/files/2" "path/to/files/3"

So I'm thinking for this the fix is Daniels hook files. =)

Now I am still having issues with other parts that I don't have the time to tend to currently, but when I do I'll let you know if its working as a whole or not.

Daniel Hyams

unread,
Jun 21, 2012, 8:02:30 PM6/21/12
to pyins...@googlegroups.com
I've just verified that those two hooks above work, at least with the arg1 variation of pubsub.  I'll test with the kwarg variation, and then put up a pull request.

Daniel Hyams

unread,
Jun 21, 2012, 10:35:47 PM6/21/12
to pyins...@googlegroups.com

Daniel Hyams

unread,
Jun 22, 2012, 9:11:10 AM6/22/12
to pyins...@googlegroups.com
Tom: 

If you have time, can you verify that my changes to pyinstaller work for you?

--
Daniel Hyams
dhy...@gmail.com

Sebastian Hilbert

unread,
Jun 22, 2012, 1:44:05 PM6/22/12
to pyins...@googlegroups.com
On Thursday, June 21, 2012 04:36:34 PM Tom Tijerina wrote:
> What are you using instead of wx, if I may ask.

We are still using wx but we got rid of pubsub for the moment.

Sebastian

Tom Tijerina

unread,
Jun 25, 2012, 3:43:00 AM6/25/12
to pyins...@googlegroups.com
Sorry it took me awhile for an update Daniel.

I just downloaded a new copy, and I believe I fixed the mechanize issue, now I'm running back into publisher issues.

To eliminate a few of the other libraries I used I did a quick google on a simple wx pubsub demonstration. I came up with this site: http://www.blog.pythonlibrary.org/2010/06/27/wxpython-and-pubsub-a-simple-tutorial/  I have tested his code, it behaves exactly the same way as mine. If you have wx installed and figure something out please let me know. :)


Below is a table of import to errors encountered trying to run the onefile exe from both the test and from my script. I hope somehow it can help.

from wx.lib.pubsub import Publisher

C:\Documents and Settings\Tom>"C:\Documents and
-pyinstaller-1045a28\dist\startme.exe"
Traceback (most recent call last):
  File "<string>", line 7, in <module>
ImportError: cannot import name Publisher

from wx.lib.pubsub import setupv1
from wx.lib.pubsub import Publisher

C:\Documents and Settings\Tom>"C:\Documents and Settings\Tom\Desktop\pyinstaller
-pyinstaller-1045a28\dist\startme.exe"
Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\Py
Installer\loader\iu.py", line 431, in importHook
    mod = self.doimport(nm, ctx, ctx + '.' + nm)
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\Py
Installer\loader\iu.py", line 480, in doimport
    exec co in mod.__dict__
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\bu
ild\pyi.win32\startme\out00-PYZ.pyz\wx.lib.pubsub.setupv1", line 16, in <module>

  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\bu
ild\pyi.win32\startme\out00-PYZ.pyz\wx.lib.pubsub.pubsubconf", line 16, in setVe
rsion
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\bu
ild\pyi.win32\startme\out00-PYZ.pyz\wx.lib.pubsub.pubsubconf", line 51, in setVe
rsion
AssertionError


A this point I adapted my code from V1 code to V3 code by changing Publisher().* to Publisher.*

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

----OR-----
from wx.lib.pubsub import setupkwargs
from wx.lib.pubsub import pub as Publisher

C:\Documents and Settings\Tom>"C:\Documents and Settings\Tom\Desktop\pyinstaller
-pyinstaller-1045a28\dist\startme.exe"
Traceback (most recent call last):
  File "<string>", line 7, in <module>
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\Py
Installer\loader\iu.py", line 431, in importHook
    mod = self.doimport(nm, ctx, ctx + '.' + nm)
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\Py
Installer\loader\iu.py", line 480, in doimport
    exec co in mod.__dict__
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\bu
ild\pyi.win32\startme\out00-PYZ.pyz\wx.lib.pubsub.pub", line 24, in <module>
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\Py
Installer\loader\iu.py", line 386, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\Py
Installer\loader\iu.py", line 480, in doimport
    exec co in mod.__dict__
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\bu
ild\pyi.win32\startme\out00-PYZ.pyz\wx.lib.pubsub.core.listener", line 13, in <m
odule>
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller-pyinstaller-1045a28\Py
Installer\loader\iu.py", line 409, in importHook
    raise ImportError("No module named %s" % fqname)
ImportError: No module named listenerimpl



Sorry again that it took so long for a reply, 

Tom

Daniel Hyams

unread,
Jun 25, 2012, 8:43:19 AM6/25/12
to pyins...@googlegroups.com
Tom:

I'm afraid that the download from github might not be working like I thought it does; you might just be redownloading the "develop" branch from github, which does not have the wx.lib.pubsub fixes merged in yet.  To verify, see if a hook with "setuparg1" in the name exists in PyInstaller/hooks.

Tom Tijerina

unread,
Jun 25, 2012, 5:21:11 PM6/25/12
to pyins...@googlegroups.com
Daniel, 
I just got it from the github, I didn't find that file from what I got in git, or in what I had downloaded from development zip. I'm not sure if I'm looking in the correct place. The only file with that name that I can find is in C:\Python27\Lib\site-packages\wx-2.8-msw-ansi\wx\lib\pubsub however I did check and I found this in the log:

12312 INFO: Hidden import 'wx.lib.pubsub.core' has been found otherwise
12312 INFO: Analyzing hidden import 'wx.lib.pubsub.setuparg1'
12359 INFO: Hidden import 'encodings' has been found otherwise

Wouldn't that mean that it did find it, versus complaining that it couldn't find it?

-Tom

Daniel Hyams

unread,
Jun 25, 2012, 6:34:28 PM6/25/12
to pyins...@googlegroups.com
I'm guessing that you didn't get the correction version (not your fault, but just the way it goes).  I'm pretty confident that it is working, since I can put together a test case that demonstrates a before/after.  So don't worry about it....perhaps wait until the merge of my pull request, and then try.

Tom Tijerina

unread,
Jun 25, 2012, 6:36:20 PM6/25/12
to pyins...@googlegroups.com

Just let me know when. :)

Thanks

Tom Tijerina

unread,
Jun 26, 2012, 12:50:32 AM6/26/12
to pyins...@googlegroups.com
I went and manually put the hook files back in. I'm still having issues with the wx library, I'm not sure if this is related or not. 


C:\Documents and Settings\Tom\Desktop\pyinstaller>"C:\Documents and Settings\Tom
\Desktop\Tom\dist\startme.exe"
Traceback (most recent call last):
  File "<string>", line 8, in <module>
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller\PyInstaller\loader\iu.
py", line 386, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller\PyInstaller\loader\iu.
py", line 480, in doimport
    exec co in mod.__dict__
  File "..\Tom\build\pyi.win32\startme\out00-PYZ.pyz\irep", line 10, in <module>

  File "C:\Documents and Settings\Tom\Desktop\pyinstaller\PyInstaller\loader\iu.
py", line 386, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller\PyInstaller\loader\iu.
py", line 480, in doimport
    exec co in mod.__dict__
  File "..\Tom\build\pyi.win32\startme\out00-PYZ.pyz\GUI", line 74, in <module>
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller\PyInstaller\loader\iu.
py", line 386, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "C:\Documents and Settings\Tom\Desktop\pyinstaller\PyInstaller\loader\iu.
py", line 480, in doimport
    exec co in mod.__dict__
  File "..\Tom\build\pyi.win32\startme\out00-PYZ.pyz\GUI.Colors", line 27, in <m
odule>
AttributeError: 'module' object has no attribute '_from_win_color'

C:\Documents and Settings\Tom\Desktop\pyinstaller>


Reply all
Reply to author
Forward
0 new messages