Bundle Python framework into Xcode app
macos, pyobjc, python, xcode, xcode4.5
Solution
Don't try to copy /System/Library/Framework/Python.framework into your application bundle, that almost certainly won't do what you want (the application won't work on older OSX releases, and isn't necessary on the same or newer OSX releases), and is dodgy license wise.
To use the framework you need to rewrite the load commands, either by using install_name_tool, or by creating a custom python framework that already has the correct value for the install name (something like @executable_path/../../Framework/Python.framework/Python.
I usually use py2app to create the application bundle (not unsurprisingly, as I'm the maintainer for py2app), that will automaticly include the required Python dependencies as well.
Problem
I am building a PyObjC app using Xcode 4.6.2 and am trying to figure out how to bundle the Python framework in with my app, so that I can reference it without relying on the host system having a particular Python version. (I previously asked this question, but since then, I've decided that embedding the framework is the better way to go.) I know this is a thing that people do -- in my experience, most standalone Python apps package a Python installation within them. But I can't figure out how to get it to work for me. I have copied Python.framework into my project using the Build Phases "Copy Files" panel, and Python.framework does show up in my app bundle, but I can't figure out how to get the application to reference it. If I link to Python.framework in "Linked Frameworks and Libraries" in Xcode, the app builds properly, but fails on launch on 10.6 with the error ``` Dyld Error Message: Library not loaded: /System/Library/Frameworks/Python.framework/Versions/2.7/Python Referenced from: {/path/to/my/app} Reason: image not found ``` ...because 10.6 only has Python 2.5, and it's searching for the system framework, not the one included in my app bundle. If I don't link to the Python framework in Xcode, the app fails to build. So how do I tell my application that I want it to use the Python.framework bundled inside my app at `appname.app/Contents/Frameworks/Python.framework`, and NOT the system Python.framework located at `/System/Library/Frameworks/Python.framework`? I'm at a bit of an impasse with this issue, and any help would be greatly appreciated.