[Pythonmac-SIG] [py2app] No module named os

Chris Weisiger cweisiger at msg.ucsf.edu
Fri Aug 20 23:48:10 CEST 2010


I'm trying to use py2app to generate a standalone executable of a program
I've made (major dependencies: wx, OpenGL, numpy/scipy). I've done this
successfully several months ago, as evidenced by horribly out-of-date
versions of the program that my users are still using because I can't get a
newer version to work on their systems! I remember getting the thing working
to be a bit of a chore, but unfortunately I didn't take notes on what all I
did. Presumably the apps generated by py2app should not be dependent on
changes that my users have made to their own systems.

Doing "python setup.py py2app" apparently works, generating dist/editor.app
which runs fine on my own computer. However, when run on a computer that is
not my computer, I get the error "no module named os" and the program exits.
Specifically, here's the complete error log from Console.app:

8/20/10 2:26:59 PM [0x0-0x1ad1ad].org.pythonmac.unspecified.editor[12219]
'import site' failed; use -v for traceback
8/20/10 2:26:59 PM [0x0-0x1ad1ad].org.pythonmac.unspecified.editor[12219]
Traceback (most recent call last):
8/20/10 2:26:59 PM [0x0-0x1ad1ad].org.pythonmac.unspecified.editor[12219]
File "/Volumes/KINGSTON/editor.app/Contents/Resources/__boot__.py", line 4,
in <module>
8/20/10 2:26:59 PM
[0x0-0x1ad1ad].org.pythonmac.unspecified.editor[12219]     _chdir_resource()

8/20/10 2:26:59 PM [0x0-0x1ad1ad].org.pythonmac.unspecified.editor[12219]
File "/Volumes/KINGSTON/editor.app/Contents/Resources/__boot__.py", line 2,
in _chdir_resource
8/20/10 2:26:59 PM
[0x0-0x1ad1ad].org.pythonmac.unspecified.editor[12219]     import os
8/20/10 2:26:59 PM [0x0-0x1ad1ad].org.pythonmac.unspecified.editor[12219]
ImportError: No module named os
8/20/10 2:26:59 PM editor[12219] editor Error

(Incidentally, this used to complain about being unable to import traceback,
until I turned off argv emulation)

Some Googling suggested that I try unsetting environment variables at the
start of my script as they might be interfering. So I added this to the top
of my script:

import os
for key in ['PYTHONPATH', 'PYTHONHOME', 'PYTHONEXECUTABLE']:
    if key in os.environ:
        del os.environ[key]

No dice. I tried manually inserting that same code into the top of
__boot__.py; the only difference then is that it crashes at that "import os"
invocation instead of the normal one.

I thought maybe that I was using the wrong version of Python -- I know
there's some annoying weirdness with py2app refusing to use the standard
Python install. I have /usr/bin/python2.5, /usr/local/bin/python2.5 (the
official install?), and /opt/local/bin/python2.5. The first one generates
apps successfully, the second barfs because it can't find main-i386 even
when I symlink main-fat3 to it, and the last doesn't have setuptools and
therefore is presumably not the one I've used in the past. I haven't changed
dependencies for the app itself since I last made a working app, and I know
that it wasn't a Python 2.6 app.

My setup.py script is as follows:

from setuptools import setup

APP = ['editor.py']
DATA_FILES = ['Priithon']
OPTIONS = {}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

Any advice? Suggestions? I've run out of  ideas myself.

-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20100820/cb557328/attachment.html>


More information about the Pythonmac-SIG mailing list