0

I am using Xcode to build a PyObjC application. The app runs fine on the build machine (running 10.8) but crashes on startup on a machine running 10.6, because it fails to find the Python 2.7 installation. Fair enough -- the preinstalled Python on 10.6 is Python 2.5. But I don't really care which Python version my app uses, I just want it to use the latest version of Python it can find.

How can I either:

A) Tell my app to use the latest version of Python available on the host system, OR

B) Bundle the entire Python source into my app?

I have been very frustrated by this issue and any help would be greatly appreciated!

ekl
  • 1,052
  • 2
  • 9
  • 24

2 Answers2

0

Good question. I wrestled with this for an embedding problem a few years ago and ended up dynamically linking against a specific version that I knew was available on every platform.

I had assumed originally that the Python.framework's Current would be adequate, but it seems to get resolved at link time by Xcode, therefore making the link specific to a particular version. For my purposes, I was able to link directly to

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/Python

Which works for OS X 10.7 and 10.8. If you need to go back to 10.6, you'll want to try linking to

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Python.framework/Versions/2.5/Python

Obviously, if you're compiling against the 10.6 SDK, you'll want to use that, but the key is to make sure that you link to a version-specific version of the libraries and not the framework version itself. You should be able to manually navigate to the specific version through the + button in the Link Binary with Libraries, but if you have problems, you can open the Python.framework from the SDK directly in the Finder and drag the version-specific library into the Link Binary with Libraries group.

If you find a way around this, then please post another answer here, but this was effective for me to link for embedding into my app.

gaige
  • 17,263
  • 6
  • 57
  • 68
  • Thank you for the help! This may be a stupid question, but how can I navigate to the Python framework via the Link Binary with Libraries panel? I would normally right-click on Xcode.app and "Show Package Contents", but the selection dialog doesn't seem to allow me to do that. – ekl Jul 29 '13 at 15:02
  • Edit: Figured it out using a workaround -- navigated to it in the Finder and added it to my Finder sidebar so I could click on it in Xcode. – ekl Jul 29 '13 at 15:10
0

Use py2app to create the application bundle, and do that using a separate install of Python (that is don't use /System/Library/Framework/Python.framework). The python install you use should be compiled with the MACOSX_DEPLOYMENT_TARGET set to the minimum OSX release you want to support.

When you do this, it should be possible to deploy to older OSX releases. I regularly do this for building apps on a 10.8 machine that get deployed to a 10.5 machine.

You do need to take some care when including other libraries, especially when those include a configure script: sometimes the configure script detects functionality that is available on the build machine, but not on the deployment machine.

BTW. You need to link against the same version of Python as you use at runtime. CPython's ABI is not compatible between feature releases (that is, the 2.6 ABI is not necessarily compatible with the 2.7 ABI). For python 3.x there is a stable ABI that is compatible between feature releases, but AFAIK that's primarily targeting Python extensions and I don't know how useful that is for embedding Python in your application.

Ronald Oussoren
  • 2,715
  • 20
  • 29