1

I'm trying to create an exe file with PyInstaller (one-file mode). My program is a single file (usingTry.py). It's a super simple file that instantiates a class called "TrySystem" from an egg file I created. The "TrySystem" class loads an XRC file and places a bitmap button in it using wxPython. The XRC and the image files are saved as inner egg resources, as described in Managing resources in a Python project

I prepare my egg on a mac (10.8.5):

sudo python setup.py bdist_egg

I then copy it to a winXP machine (actually it runs on the same compoter as a VM) and install it:

easy_install Try\try2\dist\try3-1.0-py2.7.egg

When I then try to run "python usingTry.py" from the python terminal (on WinXP), all works fine and I see the frame and the button. I then go on to prepare an exe file from "usingTry.py" (on WinXP):

Try\users\usingTry>pyinstaller.py -F usingTry.py

And then I try to run it:

Try\users\usingTry>dist\usingTry.exe

Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "<string>", line 4, in __init__
  File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\try3", line 35, in __init__
  File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\try3", line 8, in __init__
  File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\wx._core", line 7981, in __init__
  File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\wx._core", line 7555, in _BootstrapApp
  File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\try3", line 14, in OnInit
  File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\pkg_resources", line 868, in resource_filename
  File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\pkg_resources", line 181, in get_provider
  File "c:\programs\pyinstaller-2.0\PyInstaller\loader\iu.py", line 409, in importHook
    raise ImportError("No module named %s" % fqname)
ImportError: No module named try3.resources

Does someone know how to resolve this? In this link is a zip file with everything:

try.zip:
    Try/
        try2/                           (this is the code that creates the egg)
            setup.py
            ez_setup.py
            try3/                       (the egg's code)
                __init__.py
                resources/              (here are the resource files used in the egg)
                    __init__.py
                    main.xrc
                    stopButton.png
            build/   
                ...                     (files created while I built the egg)
            dist/
                try3-1.0-py2.7.egg      (the prepared egg file)
            try3.egg-info/
                ...
        users/
            usingTry/                   (here is the code that uses the egg file)
                usingTry.py
                usingTry.spec
                dist/                   
                    usingTry.exe        (created by "pyinstaller -F usingTry.py")                   
                    try3/               (I manually copied it here from Try/try2/ so the exe file works)
                build/                  (created by PyInstaller)
                    ...
                logdict2.7.5.final.0-1  (created by PyInstaller)

You'll notice that the folder Try\try2\try3 (which contains the egg's code) was manually copied to where the created exe file is (Try\users\usingTry\dist). That's because it makes the exe file work. I found this workaround in PyInstaller generated exe not working, project uses ReportLab

What I'd like to do is avoid this workaround and that things will simply work. It has to be somehing very simple as it's declared in the PyInstaller website that they fully support using egg files.

Community
  • 1
  • 1
yoel
  • 305
  • 4
  • 17
  • 1
    One thing you can do, which doesn't actually solve the problem, is include these files as data files. It'll copy them for you to the dist/ directory. What you want is probably to access the files from the egg directly though, right? That [should be possible](http://pythonhosted.org/setuptools/pkg_resources.html#resource-extraction), and I remember I had it working once. If I'm not too late to answer, let me know I might be able to help you. – jadkik94 Dec 22 '13 at 23:01
  • Yes please! I'm still waiting for someone to help me with that. – yoel Dec 23 '13 at 11:03

1 Answers1

0

I think the issue here is that when you install it using easy_install it's probably not being installed as a zipped egg. I tried this on a Linux system and that's what happened.

If you do easy_install --record INSTALLED_FILES.txt try3-1.0-py2.7.egg, you'll see the list of installed files in INSTALLED_FILES.txt.

If the files listed there are not in a zipped egg, what is happening is that PyInstaller is detecting that you want to import try3, finds it on your PYTHONPATH as an unzipped egg, and includes it as such in its own format, not an egg. And thus pkg_resources does not find it in an egg or as a "physical" file, and it breaks.

What you can probably do is:

  • Either try to install it as a zipped egg using pip or easy_install (I doubt pip would do it though)
  • Ship your egg externally, and put it in let's say ./eggs, then from your script modify the Python path to include all the eggs. (import glob, sys, os; sys.path.extend(glob.glob(os.path.join(os.path.dirname(sys.executable), 'eggs', '*.egg'))) Something like that probably) You might want that if you want to dynamically include eggs at runtime, I know I did)
  • From the spec file, explicitly include the egg. But you'd have to make sure the other try3 is not picked up, maybe there'll be a conflict. So add the egg to pathex=[..., '/full/path/to/try3-1.0-py2.7.egg', this way it'll use the egg directly and probably package directly from that.
  • And lastly, you could add these data files to the Analysis's data list, and it'll extract them to the directory of the executable. That is what I ended up doing before.

Sorry if I'm really late :) Hope it helps.

edit Oh and it might help you debugging if you look at the .toc files in the build directories. Just Ctrl+F for try3 and usingTry and you might find helpful information as to what is being included (or not included).

jadkik94
  • 7,000
  • 2
  • 30
  • 39
  • Hi jadkik, I wanted to quickly appologize for not responding yet. I thank you very much for your help and will try it as soon as I can, and write back. – yoel Jan 16 '14 at 09:04