MacOS – Linking python as external build tool in Xcode 7 El Capitan

macospythonxcode

I have been using Xcode 7 as my default python editor for some time now. The usual method to run python from Xcode is given here https://stackoverflow.com/questions/5276967/python-in-xcode-7/8636301#8636301.

But with the new release of El Capitan (OS X 10.11), the /usr/local/bin/ directory is locked and in the step in "Edit Scheme > Info > Executable" where the executable has to be selected from a pop-up window, since the SIP is enforced, this is not possible. I already own the /usr/local/ but this hasn't helped. It is worthwhile to note that this problem should not be python version specific.

Can somebody suggest a workaround for this?

I know I will receive suggestions for using other editors and engines such as Eclipse and Canopy, but no thank you (no offence to Eclipse or Enthought of course).

Best Answer

My system is OS X 10.11 El Capitan with SIP enabled, with Xcode 7.2.1, and the following solution work for me.

The solution briefly: for your executable, select the Python installed in your system, which resides in:

Python.framework/Versions/ (3.x or 2.7) /Python

The location of Python.framework depends on which distribution of Python you're using. Most often it can be found in /Library/Frameworks.

More comprehensive directions below.


Edit your Xcode scheme:

  1. Select Product > Scheme > Edit Scheme
  2. Run > Info > Executable > Other
  3. Press Cmd(⌘)+Shift+G and type in the place where your Python executables are installed.
  4. Select "Python" executable file.

Now, the place where the actual executables varies, depending on which Python distribution you chose to install. None of those, to my knowledge, place anything but symlinks to /usr/local/bin or /opt/local/bin. Below, I'll provide directions to finding your Python executable file.


MacPython

This is the version from the official Python website, and it resides in /Library/Frameworks/Python.framework.

ActiveState ActivePython

Installs to the same directory as MacPython.

MacPorts

MacPorts installs its python to /opt/local/Library/Frameworks/Python.framework.

HomeBrew

HomeBrew has two possible locations for your Python.framework, because unlike any other distribution, HomeBrew installs them separately.

  • python2 in /usr/local/Cellar/python
  • python3 in /usr/local/Cellar/python3

Inside either of them, you'll find Frameworks/Python.framework.

All distributions

Inside any Python.framework, you'll want to open a folder named Versions. Inside, you'll find folders corresponding to Python versions installed on your system. Open whichever one you want to use, and inside You'll find an executable named Python. You're done!