5

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).

  • I thought /usr/local was not covered by SIP – user151019 Oct 7 '15 at 11:35
  • Thanks @Mark. It looks like /usr/local/ is not supposed to be covered by SIP, but selecting the executable is still not possible, even though I own the /usr/local/ and the permissions are lrwxr-xr-x. Any idea what might be going wrong? – xen Oct 7 '15 at 11:45
  • 1
    I'm also keen on the solution, I've not upgraded to El Capitan yet due to MySQL issues, but not being able to use Python in XCode anymore is also an issue. – Ewald Dec 16 '15 at 13:26
  • 1
    @Ewald: You could possibly run everything fine by disabling the SIP, which is similar to the SELinux. I realised that the SIP definitely doesn't allow even the native python (2.7) to be linked. This is what I got at debugging with the native python on Xcode: Message from debugger: cannot attach to process due to System Integrity Protection – xen Dec 17 '15 at 16:40
  • 1
    That "possibly" is what's keeping me from upgrading. A colleague updated and now his MySQL is all broken, I just can't take the chance with my development machine. No work equals no pay for me so I'll patiently wait - at least I still have my Windows laptop and Python development works great on that! – Ewald Dec 18 '15 at 7:43
2

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!

1

trying run Python 2.7.11 on Xcode 7.2 on OS X 10.11.2; I could not select 'python' under "Edit Scheme" > "Info" > "Executable" It was grayed out. I do not know what SIP means, but I got it to work by right-clicking the grayed out 'python' under usr/local/bin in the window and selecting "Quick Look" A box opened and I closed it and 'python' was now selectable and ran the file like a champ! 

  • 1
    Your answer sounds kind of chancy. Using Quick Look doesn't change anything in your Mac, so there must be another reason you could select Python in Xcode. – Behdad Feb 10 '16 at 7:00
  • 1
    This worked for me as well: after closing the Quick Look, the Choose button was enabled. I clicked it, and all is working well! Call it an "Easter Egg", lol? – leanne Apr 9 '17 at 2:47
  • This relies on a bug in the OS X file browser window (namely, that unselectable items accidentally become selectable after the Quick Look window is used), but it's all we've got! – superbatfish Sep 7 '17 at 18:48
  • See also: stackoverflow.com/questions/37182783/… – superbatfish Sep 7 '17 at 18:51
1

I know this was posted a loooong time ago, but i ran into the same issue just now, and thought i would share my findings.

This solution worked for me.

  1. Close Xcode.
  2. Browse to you project library.
  3. Right click the project .xcodeproj file and choose 'Show Package Contents'
  4. Find the project .xcscheme file and open it in a editor.
  5. Find the PathRunnable tag, and set the FilePath to "/usr/local/bin/python3"
  6. Save the file and open the project again.

This way you can use brew install python3 to install your preferred Python for Xcode.

0

When you click on "Other..." and the dialog window comes up, press shift+cmd+g. That will open a dialog box that lets you type a specific path. Just like going to a hidden directory in the Finder.

I'm on 10.11.2 running Xcode 7.2, so in my case the python executable is in /usr/bin

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .