Installing Python: Quick Tutorial for Journalism Students

Right off the bat, you’re going to learn that your ability to troubleshoot ambiguous instructions and consider all relevant variables will be key to your success as a computational journalist. Getting started with Python depends on which operating system you are using.

Python on a Mac

The easiest operating system on which to start is Apple’s OS X, which is install on all Macintosh computers. Every version of OS X ships with a default version of Python already installed. The “Lion” version of OS X — versions that begin with 10.7 — ship with Python 2.7.1 or (I think) 2.7.3. That’s great, because 2.7.3 is one of the most recent versions of Python, and the version we’ll be using here. (I’ll tell you in a bit why I say that 2.7.3 is one of the most recent versions.)

Earlier versions of OS X — such as 10.6 “Snow Leopard” — come with earlier versions of Python, such as 2.6.1 or something like that. For now at least, that’s no big prob.

Here’s how you can find out which version of Python is installed on your Macintosh:

  1. Go to Applications –> Utilities –> Terminal
  2. At the $ prompt, type “python –version”, and hit the [Return] key
  3. You should get a response that tells you what version of Python you have installed by default. Go ahead and get Python started by typing at the $ prompt: “python,” and then hitting the [Return] key

Python on Windows

Python does not come with Windows computers, so you will have to download and install it. Here’s how:

  1. Open a browser and go to https://www.python.org/ftp/python/2.7.3/python-2.7.3.msi . This will begin downloading the Python installer. It should take about 2 minutes to download.
  2. Once downloaded, double-click the installer to run it. It will take another 2 minutes to install.
  3. Unless there’s some reason not to, leave all the default choices selected.
  4. Python will be installed at C:Python27 and it will take up about 51MB of space. In your Start menu you will also see “IDLE (Python GUI)”. Let’s go ahead and launch Python now by clicking on that icon.

Python on Linux/Ubuntu/Amazon AWS

Many hard-core programmers work on some flavor of the free Linux operating system. Ubuntu is the version I use. You can install Ubuntu as an alternate operating system on either a Mac or a Windows PC. On my Mac, I use the freely available Virtual Box application from Oracle to create what’s called a virtual machine that allows me to run Ubuntu in RAM while I’m also working in the OS X operating system. But you can also install Ubuntu on your Mac using Apple’s own Boot Camp application (which you can find in Utilities) or a program called Parallels. I will say that Virtual Box is not particularly user friendly, and Boot Camp might be your best bet.

You can also install Ubuntu as an alternate operating on a Windows computer by using the instructions at https://www.ubuntu.com/download/help/install-ubuntu-with-windows

Finally, at some point you will want to put the applications you write in Python on the Web. To do that, you’ll need access to a Web server. Probably the easiest and cheapest place to start is the EC2 service from Amazon Web services, by going to https://aws.amazon.com. The upside of using AWS is that you can launch within minutes a Web server running the most recent version of Ubuntu and Python, and the cost is $1-$15 per month unless you do some heavy work. The downside is that security configuration that allows you to connect to create Python programs by using the “command line” — the Terminal on a Mac or on a Windows PC — can be a bit hairy. But you’ll have to learn how to do it eventually so now might as well be the time.

Troubleshooting

By now you should have a version of Python up and running on either a Mac, a PC or on a remote service like Amazon EC2. Or… you might have run into trouble. Most trouble you encounter is going to be because you’re reading instructions that differ, in some small way, from the operating system you’re using or the version of Python you’re using, or a thousand other small things. When you’re Googling for tutorials or forums on Linux, be sure you know the numerical version of your operating system and your version of Python. But even that may not be enough, because many authors have written their tutorials using outdated versions or they aren’t clear about which versions they’re using. Get used it. Be skeptical. Go slowly. Be calm.

Two potential errors I want to check with you right now:

  1. Don’t use any flavor of Python 3. Use only Python 2. Right now there are two “branches” of Python, and all of the applications we’re using will require Python 2. In this case, bigger is not better.
  2. On a Mac — and Ubuntu to some degree — be careful when you feel a temptation to “upgrade” to a new version of Python. Python comes with Macs for a reason — the operating system needs it to be a certain version in a certain location. Change it and things can get messed up beyond my ability to explain it. The built-in version of Python on a Mac will be at /System/Library/Frameworks/Python.framework and /usr/bin/python. If you install a different version, it — in an ideal world — will be at /Library/Frameworks/Python.framework. You should be able to use the command line in Terminal to navigate to those directories, and if you don’t know how to do that now is the time to ask a human for help. Your likelihood of finding the answer via Google will be inefficient at beast and frustrating at worst.



 

Print Friendly, PDF & Email