When it has finished installing, enter brew --version to check it's installed. And brew home to open the Homebrew webpage and learn how to use Homebrew.
Packages are installed using brew install. Unlike apt-get you don't need to use sudo with brew. (Don't worry if that previous sentence doesn't make sense! You'll get the hang of it as you start to learn Python.)
Install PIP in OS X
PIP is a program used to install Python packages (these are pre-built blocks of code you'll be using inside your programs). Installing PIP is easy. Open Terminal and enter this line: sudo easy_install pip. Enter pip --version to make sure it's installed.
The best Python text editors for Mac
By default, Python files (ending in .py) will open in TextEdit, and this won't do. It has a nasty habit of a writing files in non-ASCII format, which messes things up. It also lacks any decent formatting options.
So you'll need to install a great text editor. Fortunately, there are a few available. Here are the three best text-editing applications for Mac.
- TextWrangler: This app is a free download from the App Store. It's a lightweight version of BBEdit but has all the functionality you need. The best choice for starting out.
- Geddit: This is a popular choice amongst Linux fans, so it's good for programmers to learn. Not as slick as other options, but very functional.
- Sublime Text: This is my personal favourite. You can download and use it for free, although it'll occasionally nag you into paying for it. A slick interface that's easy on the eyes with great formatting control.
When you've installed your text editor, it'll be important to associate it with Python files (ending in "py".):
- Open the text editor and save a file called "test.py" to your desktop.
- Highlight the file and choose File > Get Info (Command-I).
- Change the option under Open With to your program of choice.
- Click Change All.
Create a "Hello, World!" program
Now that you've got Python installed correctly, let's see how easy it is to create a Hello World program. "Hello, World!" is a standard first program that simply writes the words "Hello, World!" to the screen.
- Open Terminal.
- Enter touch helloworld.py to create a blank Python text file.
- Enter open helloworld.py. The file should open in the app you chose in the previous step.
- Enter a single line in the text file that reads: print "Hello, World!"
- Save the file (Command-S).
- Head back to Terminal and enter python helloworld.py.
Sign up for CIO Asia eNewsletters.