View Full Version : Python on Mac
Jacksteruk309
May 31, 2005, 03:30 PM
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
May 31, 2005, 04:01 PM
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 (http://homepages.cwi.nl/~jack/macpython/download.html), 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 (http://www.python.org/download/).
Jacksteruk309
May 31, 2005, 04:25 PM
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
Omen88
May 31, 2005, 04:55 PM
in the terminal:
python <nameofyourfile.py>
Or am I missing something special you want to do?
Loge
May 31, 2005, 05:01 PM
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.
Jacksteruk309
May 31, 2005, 05:09 PM
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
superbovine
May 31, 2005, 10:19 PM
edit figured it out
WebMongol
Jun 1, 2005, 02:01 AM
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
Jun 1, 2005, 05:34 PM
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
Jun 2, 2005, 01:34 AM
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.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.