Very stupid question about Python on OS X

Durandal
Unregistered
 
Post: #1
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
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
open Terminal,
cd into the folder the script is in
python script.py

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #3
How are you trying to run it? Through some sort of IDE or someting? That would be helpful to know.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Durandal
Unregistered
 
Post: #4
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
You wouldn't normally run a python script from the GUI on Mac OS X. Follow unknown's instructions above.
Quote this message in a reply
Durandal
Unregistered
 
Post: #6
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
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.
Quote this message in a reply
Durandal
Unregistered
 
Post: #8
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.
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #9
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
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2008.08
Post: #10
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
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #11
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.

It's not magic, it's Ruby.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Python for games? DEV_JS 2 2,627 Apr 12, 2013 05:15 PM
Last Post: Evan Stallings
  Python Compiler wyrmmage 3 4,100 Jul 30, 2009 10:14 PM
Last Post: wyrmmage
  Text based RPG in Python pipposanta 7 8,402 Feb 27, 2008 09:10 AM
Last Post: pipposanta
  Python question: require users to install libs? stevejohnson 2 4,010 Feb 1, 2008 03:22 AM
Last Post: aqua_scummm
  So... anyone doing any stuff in Python/Pygame...? Malarkey 12 6,738 Aug 23, 2007 12:09 PM
Last Post: Malarkey