Search code examples
pythonpublish-subscribepyinstaller

How to get pubsub to work with pyinstaller?


I'm trying to use pyinstaller to build an exe from my python code. One of the modules I'm using is pubsub (pypubsub really. It used to be a part of wxpython). I'm getting errors when I try to run the exe. It complains "ImportError: No module named listenerimpl".

I've seen some articles about getting wx.lib.pubsub to work (it has known issues with pyinstaller). I've tried the solutions presented in those articles (slightly modified to account for it not being a part of wx anymore) but no luck.

I can get past the initial "ImportError: No module named listenerimpl" error by adding the path to the right listenerimpl (the kwargs one) to the list of files for Analysis in my spec file but then I hit further errors on importing "publisher". That error isn't fixed by adding its path in the spec file.

I think the solution shouldn't involve adding the path to listenerimpl.py in my spec file... but I'm not sure how to get this working happily.

extra info

  • using pubsub version: 3.1.1b1.201005.r243
  • using pyinstaller version: 2.0
  • platform: win7

Solution

  • pubsub problems solved (although exe still not running).

    So if you look at comments here (especially comment #15 by sebastian.hilbert) it mostly solves the problems with some tweaking.

    The necessary tweaks.

    1. Change the names on the hook files to hook-pubsub.core.py and hook-pubsub.setuparg1.py.
    2. Internal to those files you should get rid of references to wx.
    3. Enable the hook files. You can do this one of two ways. The easy way is to drop these new hook files into 'pyinstaller-2.0\PyInstaller\hooks' which is where pyinstaller looks for hooks by default. The clean/nice way to do this is to put these hooks into their own folder and add that folder as hookspath in your spec file.

    NB: It was not clear to me how to add a hookspath. In your specfile, in the call to Analyze, there is a hookspath arg. It wants a list not a string. So you want to do something like hookspath=['path1', 'path2', etc].

    NB2: Additionally if you ask for "path.dirname(path.abspath(__file__))" you will get the directory for pyinstaller not the location where your spec file lives.