Mac Python on Mac

JD92

macrumors 6502a
Original poster
Apr 14, 2005
934
30
I've been trying learn Python on Windows for a week or two now and I just made the switch to Mac. Me and my friend like to mess about with stuff like this, and he uses Windows, so we'll be writing code on one platform and then doing it again on the other (he uses Windows).
I've been hearing about how OS X has Python built in, but I can't find it anywhere. Anyone have any idea where to find the IDLE? I'm running OS 10.4.1
 

Loge

macrumors 68030
Jun 24, 2004
2,679
1,147
England
You can access the built-in Python by going to a terminal window and typing "python". However, this Python does not include IDLE. For that you could download MacPython, which includes a package manager to make it easy to add further stuff like Numeric.

Alternatively, if you want the latest Python it should be straightforward to compile from source.
 

JD92

macrumors 6502a
Original poster
Apr 14, 2005
934
30
Thanks, I wrote a python program on the PC which ends in .py , how would you run a .py (or .pyw) file? It's pretty simple, doesn't use anything like Tkinter or anything fancy like that, just simple print, input and variables
 

Loge

macrumors 68030
Jun 24, 2004
2,679
1,147
England
You can run a python script from Terminal, using syntax like,

python ~/Documents/first.py

if, say, you had a python script called first.py in your home Documents folder.

Good luck with Python, btw. It's a cool language though I don't have the free time to explore it more at present.
 

JD92

macrumors 6502a
Original poster
Apr 14, 2005
934
30
Omen88 said:
in the terminal:
python <nameofyourfile.py>

Or am I missing something special you want to do?
No, I'm just totally new to this. Do you have to just put 'xyz.py' or something like 'iMac/Documents/Python.xyz.py'

EDIT: It's OK, I've figured it out
 

WebMongol

macrumors member
Sep 19, 2004
50
0
Bay Area, CA
Make Python script executable

Loge said:
You can run a python script from Terminal, using syntax like,

python ~/Documents/first.py

if, say, you had a python script called first.py in your home Documents folder.

Good luck with Python, btw. It's a cool language though I don't have the free time to explore it more at present.
You can make Python script executable and run it by typing file name.
To make python script executable you need:

- add following first line to your python file:
#! /usr/bin/python
- make you python file executable:
$ chmod +x first.py

Example:

flat:~/$ cat ./first.py
#! /usr/bin/python
print "Hello World!"
flat:~/$
flat:~/$ python first.py
Hello World!
flat:~/$
flat:~/$ chmod +x first.py
flat:~/$ ls -l first.py
-rwxr-xr-x 1 webmongol staff 40 May 31 22:46 first.py
flat:~/$./first.py
Hello World!
flat:~/$
 

Loge

macrumors 68030
Jun 24, 2004
2,679
1,147
England
Good advice, though I think the last three lines above should be -

flat:~/$ ./first.py
Hello World!
flat:~/$

That is you can now run your script without calling python on the command line.
 

WebMongol

macrumors member
Sep 19, 2004
50
0
Bay Area, CA
Loge said:
Good advice, though I think the last three lines above should be -

flat:~/$ ./first.py
Hello World!
flat:~/$

That is you can now run your script without calling python on the command line.
Thanks for correction.