Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pudquick/1495f9a8b0c5f4c73bbe to your computer and use it in GitHub Desktop.
Save pudquick/1495f9a8b0c5f4c73bbe to your computer and use it in GitHub Desktop.
An example of converting an older python.Framework Xcode project to compile in Xcode 6

When Apple moved to Xcode 5 (and later 6), they changed how you embed the Python.framework in a project: https://developer.apple.com/library/mac/technotes/tn2328/_index.html

This is a basic walkthrough of the process of conversion per that documentation for Xcode 6.

The example used here is the latest version of grahamgilbert's Crypt (at the time of this writeup): https://github.com/grahamgilbert/Crypt/tree/bdd49c849ed07fbc86d8c6f5bc31a525061d5077

(If you're viewing this via a gist blogging platform like roughdraft.io, make sure to view the original gist as there are image files included within the steps)

Open the project and make sure you're in the Project navigator view (folder icon).
Make sure you're looking at the Project settings on the right.
Select the Build Settings section.
Change the Base SDK to 10.9. Xcode 6 does not ship with 10.8 or earlier SDK.
You can build 10.8+ targeted projects against the 10.9 SDK.
Alternatively, for 10.8's SDK specifically, check out:
http://stackoverflow.com/questions/25914235/how-to-get-10-8-sdk-and-5-1-compiler-in-xcode-6
Double-click on the setting for Header Search Paths.
This will give you access to the multi-entry editor.
Use delete/the minus button to remove the old Python framework entry.
Follow the instructions at the Apple documentation linked at the top.
Specifically the section: "Listing 1: Getting compiler flags"
If you're doing it right, the path you get should be:
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
Use the plus button to add this path as the last entry for header search paths.
(You can drag the order after adding them, make sure it's last)
Find references in your project for the 'Python.h' header file.
Since this is primarily a pyObjC application project, that means the 'main.m' file.
Change the references from: <Python/Python.h>
To: <Python.h>
Right-click on the Python.framework and delete it.
Again, following the instructions from Apple above, look at:
"Listing 2: Getting linker flags"
Following the instructions, it should give you the path:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
Open that location in the Finder and look for the 'libpython2.7.dylib' file.
Drag it into the Frameworks section of the project in Xcode.
When the dialog prompts, make sure 'Copy' is *unchecked*.
Congrats, you're done!
@hashier
Copy link

hashier commented Jul 9, 2017

I set all this up with python, but how do I know add as well a python library? And how do I call it then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment