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

How to set up and learn Python coding on a Mac: Install the latest version of Python 2

How to set up and learn Python coding on a Mac

Python comes installed along with OS X, although you can make sure you have the latest version of Python by installing the current build from the Python website.

  1. Download the Mac OS X 64-bit/32-bit installer (not the PPC installer) from the Python website.
  2. Double-click the python-2.7.11-macosx10.6.pkg file in the Downloads folder.
  3. If you have Gatekeeper enabled, the installation will be blocked. Open System Preferences > Security & Privacy and click Open Anyway.
  4. Click Continue, Agree and Install buttons in the Install Python window.

Open Terminal again and enter python --version. It should now read Python 2.7.11.

Which version of Python should I use?

How to set up and learn Python coding on a Mac

One confusing aspect of Python is that there are two major versions available, Python 2 and Python 3 (each with several sub-versions). What's the difference between Python 2 and Python 3?

Python 3 is the newer version of Python, so you can be forgiven for assuming that it's the best version. "Best" is pretty relative, though, and although Python 3 introduces a lot of new features, it also introduced a lot of incompatibilities.

Because coding in Python relies on using libraries of code developed by other people, this isn't a good thing.

Also, we've found that the major learning programs, from MIT to Codecademy, all use Python 2 to explain coding. These programs won't always work if you're using Python 3. So until you know what you're doing, stick with Python 2.

Install Xcode and Command Line Tools

Now that you have Python installed you should install Xcode and the Command Line Tools. Command Line Tools install a GCC compiler, and a lot of Unix-based tools also need a GCC compiler, so this is the easiest way to get one. Although you won't use Xcode to create Python programs, it'll make life easier down the line. Follow these steps to install Xcode and the Command Line Tools.

  1. Open the App Store and search for Xcode.
  2. Click Get > Install.

The Xcode Command Line Tools are installed alongside Xcode. Test that they're installed by entering xcode-select -p. You should see /Library/Developer/CommandLineTools.

Install Homebrew

Now that we've got Python and the Command Line Tools up and running, we should get Homebrew installed. Homebrew is a program used to install packages in OS X (it's the equivalent of apt-get, a command common on Unix and Linux computers).

  1. Open a Terminal window
  2. Cut and paste this command: /usr/bin/ruby -e "$(curl -fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)"

 

1  2  3  Next Page 

Sign up for CIO Asia eNewsletters.