Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

How to set up and learn Python coding on a Mac

Lucy Hattersley | March 1, 2016
Learn to code in Python on a Mac with our guide to installation, setup and training courses

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

How to set up and learn Python coding on a Mac: Text Wrangler 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".):

  1. Open the text editor and save a file called "test.py" to your desktop.
  2. Highlight the file and choose File > Get Info (Command-I).
  3. Change the option under Open With to your program of choice.
  4. Click Change All.

Create a "Hello, World!" program

How to set up and learn Python coding on a Mac: Hello, World!

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.

  1. Open Terminal.
  2. Enter touch helloworld.py to create a blank Python text file.
  3. Enter open helloworld.py. The file should open in the app you chose in the previous step.
  4. Enter a single line in the text file that reads: print "Hello, World!"
  5. Save the file (Command-S).
  6. Head back to Terminal and enter python helloworld.py.

 

Previous Page  1  2  3  Next Page 

Sign up for MIS Asia eNewsletters.