iDevGames Forums
Very stupid question about Python on OS X - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Programming Languages & Scripting (/forum-8.html)
+--- Thread: Very stupid question about Python on OS X (/thread-4197.html)



Very stupid question about Python on OS X - Durandal - Jun 8, 2006 07:36 PM

Hey all,

I started recently as a complete newbie to programming and have been slowly teaching myself Python. I recently bought a new MacBook and, of course, I wanted to get Python up and running on it. I have the latest version of OS X and updated Python to the latest build, but when I write a script and save it with the .py extension and try and launch it, I'm get hit with a prompt that says:

"Select Python source or applet"

And it wants me to browse until I find what it's looking for and select it. The only problem is, I have no idea exactly *what* it wants me to find. I know this is probably a really silly newbie question, but I really want to figure it out so I can code on my MacBook as well as on my windows box.

Thanks so much!


-D


Very stupid question about Python on OS X - unknown - Jun 8, 2006 07:41 PM

open Terminal,
cd into the folder the script is in
python script.py


Very stupid question about Python on OS X - Skorche - Jun 8, 2006 07:43 PM

How are you trying to run it? Through some sort of IDE or someting? That would be helpful to know.


Very stupid question about Python on OS X - Durandal - Jun 8, 2006 07:50 PM

Skorche Wrote:How are you trying to run it? Through some sort of IDE or someting? That would be helpful to know.

Well, I write all my code in WingIDE, both on my PC and on my MacBook. As far as *running* it is concerned, I'm trying to run it by double-clicking the icon on my desktop instead of loading it into an IDE. Again, you're dealing with someone who claims basic ignorance in this arena - all I know is that it works on my PC when I run a .py script from my desktop and on my MacBook I get that prompt. I'm sure it's a really simple thing I'm missing, I just don't know what it is and I can't find any information on it.


Very stupid question about Python on OS X - OneSadCookie - Jun 8, 2006 08:25 PM

You wouldn't normally run a python script from the GUI on Mac OS X. Follow unknown's instructions above.


Very stupid question about Python on OS X - Durandal - Jun 8, 2006 08:42 PM

OneSadCookie Wrote:You wouldn't normally run a python script from the GUI on Mac OS X. Follow unknown's instructions above.

Intersting... I didn't know that. So python scripts have to be run from the terminal in OS X?


Very stupid question about Python on OS X - OneSadCookie - Jun 8, 2006 09:00 PM

Well, clearly you have *some* program installed that does *something* when you double-click on one... and of course it'd be possible to make a program which ran them when you double-click them... but that would be unusual. Scripts will generally open in an editor when you double-clickt them, and you'll either run them from the editor, or the terminal.


Very stupid question about Python on OS X - Durandal - Jun 8, 2006 10:49 PM

OneSadCookie Wrote:Well, clearly you have *some* program installed that does *something* when you double-click on one... and of course it'd be possible to make a program which ran them when you double-click them... but that would be unusual. Scripts will generally open in an editor when you double-clickt them, and you'll either run them from the editor, or the terminal.

Ok, I'm really feeling stupid here - I must be missing something really basic, or else I'm just being a moron. All I want is to have the terminal run the .py script when I try and double-click it from my desktop just like it does on my PC. Just in case there's a miscommunication or some wires got crossed, what I'm hearing is that isn't possible? I have to manually run it in OS X from the terminal itself? The reason I keep going in circles is I want a definite answer, because on my other computer, all I have to do is click the scipt icon and it launches.


Very stupid question about Python on OS X - PowerMacX - Jun 8, 2006 11:04 PM

Durandal Wrote:Intersting... I didn't know that. So python scripts have to be run from the terminal in OS X?
Not necessarily, you can create a double-clickable Terminal command file:
http://docs.info.apple.com/article.html?artnum=151597

Or, easier (a lot easier), download TextWrangler (free & highly recommended) and:

1. Open your python script on it
2. Add this as the first line of your python script (only needed if you didn't add the .py extension to your Python script):
Code:
#!/usr/bin/env python
3. Select Run or Run in Terminal from the "#!" menu in the menubar.

Note: If you don't name your file as something.py and forget to add the shebang line (#!), in particular if you try to run an unsaved/untitled file without it, TextWrangler will remind you so:
Quote:This file doesn’t appear to contain a valid ‘shebang’ line (application error code: 26304)
Which basically means: "I don't know if this is Python, Perl or what!" Wink


Very stupid question about Python on OS X - krimb1 - Aug 24, 2008 09:40 PM

Hey guys,

Know it's been a couple of years since this thread was opened but I think I have found a solution along the lines the OP was looking for.

It's a program called Python Launcher and is available on the MacPython website. Here's a link to the download. The package installed the Python.framework to your /Library/Frameworks/ folder and throws a couple GUI programs in /Applications/MacPython 2.5/ one of which is Python Launcher.The download was originally meant for 10.2, but it might work on later versions as well; Python Launcher in specific is giving me some trouble on 10.5 but I hear it works on 10.4 just fine.

Is that more along the lines of what you need? Smile


Very stupid question about Python on OS X - Duane - Dec 17, 2008 09:33 AM

Usually, you would run python from the command line. When you release it as a download, you package it with something along the lines of py2app.