Very stupid question about Python on OS X
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
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
open Terminal,
cd into the folder the script is in
python script.py
cd into the folder the script is in
python script.py
Sir, e^iπ + 1 = 0, hence God exists; reply!
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.
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.
You wouldn't normally run a python script from the GUI on Mac OS X. Follow unknown's instructions above.
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?
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.
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.
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 pythonNote: 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!"
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?
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?
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.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Python for games? | DEV_JS | 2 | 783 |
Apr 12, 2013 05:15 PM Last Post: Evan Stallings |
|
| Python Compiler | wyrmmage | 3 | 3,128 |
Jul 30, 2009 10:14 PM Last Post: wyrmmage |
|
| Text based RPG in Python | pipposanta | 7 | 6,248 |
Feb 27, 2008 09:10 AM Last Post: pipposanta |
|
| Python question: require users to install libs? | stevejohnson | 2 | 3,483 |
Feb 1, 2008 03:22 AM Last Post: aqua_scummm |
|
| So... anyone doing any stuff in Python/Pygame...? | Malarkey | 12 | 5,223 |
Aug 23, 2007 12:09 PM Last Post: Malarkey |
|

