In this video, I’ll demonstrate how you can use Xcode 5 to build and run Python scripts.
Pingback: Building and Running Python Scripts with Xcode 4.x | vandadnp
Thanks a lot for the video!
I have successfully do the same in Xcode 4.
It saved me a lot of time.
You’re welcome and I’m glad you found this tutorial useful :-) Check back soon.
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?
Great tutorial, VandaNP. I’ve installed Python 3.x.x and it works on the shell with command python3 and located in programs folder. Any idea how to get it work with Xcode 5?
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!
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
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!
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?
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.
Success here. Even though I use Python 3, and your original example did not work. It did work when I changed it to Print (“Hello world”)
I’m glad and thank you for letting me know.
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.
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
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.
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.
This tutorial was excellent thank you for posting
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”
This is a video tutorial only. Somethings are best explained in video but I will consider writing these here as well…
Thanks for the kind words. Also, it *is* OS X, not OS 10:
Fill in your details below or click an icon to log in:
You are commenting using your WordPress.com account. ( Log Out / Change )
You are commenting using your Twitter account. ( Log Out / Change )
You are commenting using your Facebook account. ( Log Out / Change )
You are commenting using your Google+ account. ( Log Out / Change )
Connecting to %s
Notify me of follow-up comments via email.
Notify me of new posts via email.