Issues

Issue #81 resolved

env. var. ARGVZERO & RESOURCEPATH not defined

Pierre-Louis Bonicoli
created an issue

Hi,

When I run a version of Tryton (http://hg.tryton.org/tryton) built with py2app, I encountered one problem: the environment variables RESOURCEPATH and ARGVZERO are needed but not defined:

First RESOURCEPATH: $ /Applications/Tryton.app/Contents/MacOS/Tryton Traceback (most recent call last): File "/Applications/Tryton.app/Contents/Resources/boot.py", line 7, in <module> _reset_sys_path() File "/Applications/Tryton.app/Contents/Resources/boot.py", line 4, in _reset_sys_path resources = os.environ['RESOURCEPATH'] File "UserDict.pyc", line 23, in getitem KeyError: 'RESOURCEPATH'

next ARGVZERO: $ RESOURCEPATH='/Applications/Tryton.app/Contents/Resources/' /Applications/Tryton.app/Contents/MacOS/Tryton Traceback (most recent call last): File "/Applications/Tryton.app/Contents/Resources/boot.py", line 43, in <module> _run() File "/Applications/Tryton.app/Contents/Resources/boot.py", line 31, in _run argv0 = os.path.basename(os.environ['ARGVZERO']) File "UserDict.pyc", line 23, in getitem KeyError: 'ARGVZERO'

The following command runs fine:

ARGVZERO='/Applications/Tryton.app/Contents/MacOS/Tryton' RESOURCEPATH='/Applications/Tryton.app/Contents/Resources/' /Applications/Tryton.app/Contents/MacOS/Tryton

I am using Mac OSX Moutain Lion 10.8.2, python 2.7.3, py2app 0.7.2. setup.py file is here: http://hg.tryton.org/tryton/file/ec146907c4c3/setup.py#l98

Should RESOURCEPATH always be defined ?

ARGVZERO seems used in py2app/bootstrap/boot_app.py, is there a test like in py2app/bootstrap/boot_plugin.py missing ? I don't need to set ARGVZERO env. var. when using the attached patch.

Comments (15)

  1. Ronald Oussoren repo owner

    ARGVZERO and RESOURCEPATH should be set by the application launcher (the blob of compiled C code that ends up as Tryton.app/Contents/MacOS/Tryton).

    The source code for that is in <py2app/apptemplate/src/main.c> and that should set both variables unconditionally.

    I'll have to download Tryton to see if I can reproduce the problem.

    There is some odd code in the setup.py file for Tryton:

     from modulegraph.find_modules import PY_SUFFIXES
     PY_SUFFIXES.append('')
    

    I'm not sure what that tries to accomplish, but that shouldn't affect this issue.

  2. Pierre-Louis Bonicoli reporter

    When the following lines are commented:

    from modulegraph.find_modules import PY_SUFFIXES PY_SUFFIXES.append('')

    python setup.py py2app raise an error:

    TypeError: Don't know how to handle "tryton"

    It's because app doesn't end with a .py extension (<setup.py> contains app=[os.path.join('bin', 'tryton')]) Is there a cleaner way that modifying PY_SUFFIXES ?

    os.environ doesn't contain modifications made by earlier call to setenv but when I add this ugly code:

    strcpy(buf, "import os; os.environ['RESOURCEPATH']='"); strcat(buf, getenv("RESOURCEPATH")); strcat(buf, "'"); rval = py2app_PyRun_SimpleString(buf);

    strcpy(buf,"import os; os.environ['ARGVZERO']='"); strcat(buf, getenv("ARGVZERO")); strcat(buf, "'"); rval = py2app_PyRun_SimpleString(buf);

    after py2app_Py_Initialize(); in <py2app/apptemplate/src/main.c>, problems related to environment variables disappear.

    This problem may look like this window one: http://bugs.python.org/issue16633 ?

    How would you prefer me to fix this ? Is using PyRun_SimpleString a good way ?

  3. Ronald Oussoren repo owner

    Changing PY_SUFFIXES clearly is necessary, but indicates a bug in the modulegraph package. The code that uses PY_SUFFIXES looks fishy, it uses the filename attribute of a graph node to determine if a file is a python file but should use the node's class instead. That's something I'll have to fix in modulegraph.

    Setting the two environment variables using PyRun_SimpleString shouldn't be necessary, the environment variables are set before the Python shared library is even loaded and the normal initialization of os.environ should pick them up.

    Is there anything noteworthy about the path of the directory you're building in (like whitespace in directory names, or non-ascii characters)?

    Did you build python 2.7.3 yourself or did you use a binary installer (and if so which)?

  4. Pierre-Louis Bonicoli reporter

    I checked with gdb using breakpoints, setenv is called many times before Py_Initialize.

    I run python setup.py py2app in /Users/gtkosxbuilder/tryton-2.4 directory.

    I built python 2.7.3 using gtk-osx-build-setup.sh: I follow the instructions on Tryton wiki except that in .jhbuildrc-custom i use:

    • default call to setup function
    • python 2.7.3 instead of 2.6.4
    • i didn't defined CC environment variable (i use the default gcc 4.2.1)
  5. Ronald Oussoren repo owner

    The PY_SUFFIXES problem is unrelated to this one, and I've pushed a patch to the modulegraph repository that removes the need to update PY_SUFFIXES in your setup.py script.

    The fix will be in the next release of modulegraph (0.10.3), which I intend to release at the end of the week.

  6. Arif Amirani

    I had the exact same issue with an old PyObjc project of mine that worked well with PyObjc 2.2. However with 2.4 I get the following error:

    Traceback (most recent call last):
      File "/Users/cruiser/work/stockmeter/app/dist/StockMeter.app/Contents/Resources/__boot__.py", line 7, in <module>
        _reset_sys_path()
      File "/Users/cruiser/work/stockmeter/app/dist/StockMeter.app/Contents/Resources/__boot__.py", line 4, in _reset_sys_path
        resources = os.environ['RESOURCEPATH']
      File "/opt/python2.7.3/lib/python2.7/UserDict.py", line 23, in __getitem__
        raise KeyError(key)
    KeyError: 'RESOURCEPATH'
    2012-12-27 10:09:38.853 StockMeter.app[88156:707] StockMeter Error
    
    """
    Usage:
        python setup.py py2app
    """
    from setuptools import setup
    from glob import glob
    
    filelist = list(glob('resources/*'))
    print str(filelist)
    
    setup(
        data_files=filelist,
        app=['StockMeter.py'],
        install_requires=["pyobjc"],    
        setup_requires=["py2app"],
        options=dict(py2app=dict(
                plist='Info.plist',
                frameworks=glob("*.framework"),
            )),    
    )
    
  7. Arif Amirani

    Regular unix build. Configured using:

    ./configure --with-universal-archs=intel  --enable-universalsdk=/ --prefix=/opt/python2.7.3 --enable-shared
    

    I also tried one without --enable-shared and it failed py2app and complained about a missing libpython2.7.dylib

  8. Ronald Oussoren repo owner

    I don't have a solution at the moment.

    BTW. A build without --enable-shared won't work because py2app needs the python shared library to copy it into the application bundle.

  9. Ronald Oussoren repo owner

    (Reply via rona...@mac.com):

    I now have a solution: this is a bug in Python and the issue will be fixed there.

    The next release of py2app will bail out when it detects a broken python version, to avoid the very confusing behavior you ran into.

    Sent from my iPhone

  10. Log in to comment