Closed ronaldoussoren closed 11 years ago
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
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.
Original comment by Pierre-Louis Bonicoli (Bitbucket: pilou_, ).
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 (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 ?
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
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)?
Original comment by Pierre-Louis Bonicoli (Bitbucket: pilou_, ).
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:
setup
functionOriginal comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
The gtk-osx-build-setup.sh script appears to build unix-style ("--enable-shared") build of Python and not a framework build. This might be related to http://bugs.python.org/issue1602133 (but could just as easily not be).
I'll have to build python with --enable-shared to check if I can reproduce the issue that way.
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
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.
Original comment by Arif Amirani (Bitbucket: kontinuity, GitHub: kontinuity).
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"),
)),
)
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
Arif: is the python version you are using a framework build or a regular unix build?
Original comment by Arif Amirani (Bitbucket: kontinuity, GitHub: kontinuity).
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
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
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.
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
Getting closer. I can reproduce this issue with a plain unix build of python.
This appears to be related to 'http://bugs.python.org/issue1602133', that's the only difference for environment variables between a framework build and a unix build.
The easiest workaround for now: build python as a framework (or use the binary installer on www.python.org), not a unix build.
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
(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
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
As mentioned earlier this problem is caused by python bug 'http://bugs.python.org/issue1602133'. I have a patch for that bug and intend to commit that (to the python repository later this week, just before the 2.7.4rc1 release).
I will not work around the issue in py2app.
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
I've committed the patch for #1602133 in Python's tracker, and closed that issue
Original report by Pierre-Louis Bonicoli (Bitbucket: pilou_, ).
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
_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
_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.