Build and Run Python Scripts Using Xcode 5

Edit 1 (20th October 2014): Xcode 6.1 instructions can be found here: http://vandadnp.wordpress.com/2014/10/20/building-and-running-python-scripts-with-xcode-6-1/

In this video, I’ll demonstrate how you can use Xcode 5 to build and run Python scripts.

About these ads

23 thoughts on “Build and Run Python Scripts Using Xcode 5

  1. Pingback: Building and Running Python Scripts with Xcode 4.x | vandadnp
  2. Great tutorial! Thanks very much. I followed the same steps for Xcode 4 (haven’t got round to upgrading yet) and it works really well. Page bookmarked for future reference.
    Just one quick query. If the Python script contains something like inputString = raw_input(“Enter string: “), the “Enter string” text appears in the output window but it doesn’t allow anything to be entered via the keyboard. Is this feasible?

  3. Hello,

    Do you know how to configure the preferences in Xcode 5.0.1 so as to have automated indentation when loops are employed ?
    In Xcode 3.2.6 preferences weresimpler and so much better which is not the case in 5.0.1.
    Tab width 4, Indent width 4 and Syntax-aware indenting “In leading white space” are not enough any more!
    Thanks

  4. Hi,

    For some reason the debugger won’t stop at the set breakpoints, does that have anything to do with the fact, that we set the debugger to “NONE” when we change the Scheme settings?

    Thanks a lot

  5. Hi! Thanks for the tutorial. I have a question: If I create two “test.py” files… maybe test1.py and test2.py. How can I run the codes independently? I follow your tutorial, but when I create a second .py file, and if I type print “Hello!” in this second file, when I run the code, the code that runs is only the code in the first created file. (Sorry if I didn’t make my question clear). Thanks!

  6. I’ve installed Xcode 5.0.2 (5A3005) on my iMac, which is running OSX 10.9.1 with no updates available. Processor is Intel Core i5. I followed the instructions in http://vandadnp.wordpress.com/2013/07/11/build-and-run-python-scripts-using-xcode-5/.

    I follow the example and enter
    print “Hello world”
    You can’t see what happens in the example, but you must have gone to the Xcode menu, clicked Product/Run. You get a message “can’t open file ‘test.py’” etc on part of the window. I get an error box with message “Xcode cannot run using the selected destination. Choose a destination with a supported architecture in order to run on this system.” I click the OK button.

    I click in the top bar Testing Python/Edit Scheme/Run python2.7 Debug/Options tab. I click in the Working Directory box, then in the file directory which opens, select Desktop\Testing Python, press Choose, press OK. However, I again get an error message box as above. I do get a “Build Succeeded”.

    Legend in active scheme RH drop-down is My Mac 64-bit.

    Can you tell me how to avoid the error message, please?

  7. Googled the error message. Someone on cocoabuilder.com was having a similar problem; they found a workaround by changing the active scheme to “My Mac 32 bit”. I have just done this in Xcode and I can run a simple program without getting the error message. I don’t like doing this without knowing why it works (will it have unintended consequences?), but I’ll be pragmatic and use it for now.

  8. I am having the same issue as Phil:

    “Great tutorial! Thanks very much. I followed the same steps for Xcode 4 (haven’t got round to upgrading yet) and it works really well. Page bookmarked for future reference.
    Just one quick query. If the Python script contains something like inputString = raw_input(“Enter string: “), the “Enter string” text appears in the output window but it doesn’t allow anything to be entered via the keyboard. Is this feasible?”

    how do we fix this?

    • PS>Further note on setting the Executable: Typing “which python” in the terminal window shows the path as /Library/Frameworks/Python.framework/Versions/2.7/bin/python however when I try to use that path after ShiftCmdG I get the message “The folder “python” can’t be opened because you don’t have permission to see its contents.” Hence I used /usr/bin/python. Am unsure how to change the permissioning if this is my problem.

  9. I am running my own install on 2.7.6 and nltk on a Mac with 10.9.2. If I use the 2.7.6 shell I can run Import nltk without a problem however when I use Xcode to run the same code I get the message “ImportError: No module named nltk”. I have set the executable in the Info tab to use/bin/Python. Any ideas on how to fix this? I think I have a path error somewhere….. many thanks

  10. If I were to build a very simple program with Python after following your instructions, how/where can I interact with the program?
    I can’t find a way to do this, the debugger window on the bottom shows the initial prompts for my program, but I can not enter any info into it.
    Please help!

  11. Hi! Your tutorial is great but unfortunately I’m not getting the text printed on the screen. Instead I get this printed: “Python 2.7.5 (default, Aug 25 2013, 00:04:04)
    [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> ”
    What am I doing wrong?

    Thanks in advance.
    Mario

  12. I appreciate the effort.
    1. It would be nice to see these instructions in print.
    2. I hate to be pedant, but it’s pronounced OS Ten, not OS “ex”
    thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s