views:

224

answers:

3

I use Python 2.6 more than I use Leopard's default python installation, so I have it set as my main Python installation. But I'd rather use the default Python for a PyObjC program I'm working on. Is there any way to specify to only use it instead of Python 2.6?

+1  A: 

Try specifying the full path to the Python interpreter in the command line, something like:

/foo/bar/python2.6 script.py
/baz/python objcscript.py

You can also add a shebang to the beginning of your script (first line):

#! /foo/bar/python2.6 script.py

If you have the environment variable PYTHONPATH set, you might have to unset it or change it.

pts
PyObjC embeds the python interpreter in an objective-c program, so I'm not running the source file directly. Thus, I can't use a shebang line or specify the full path to the python executable at the command line.
Jason Baker
+2  A: 

AFAIR this helped me (in main.m):

    NSArray *pythonPathArray = [NSArray arrayWithObjects: resourcePath, [resourcePath stringByAppendingPathComponent:@"PyObjC"], @"/System/Library/Frameworks/Python.framework/Versions/Current/Extras/lib/python/", @"/Library/Python/2.5/site-packages", nil];

Also, make sure that this point to the Python installation you want to use (main.m):

    Py_SetProgramName("/usr/bin/python");
piobyz
That's very helpful indeed. However, this appears to actually be an issue of linking to the correct library, so by the time the program gets to calling these functions, it's already using the wrong Python.
Jason Baker
+2  A: 

Finally figured this one out myself. The key to this is to make the final executable link with /System/Library/Frameworks/Python.framework instead of /Library/Frameworks/Python.framework.

Jason Baker