Getting started in Python

There seem to be many ways to get up and running with Python, and these fall into a few main categories:

  1. Don’t install anything. You can actually get up and running with Python with no install at all by using Wakari, which is basically computing in the cloud. Time to set up: ~2 mins.
  2. Install a distribution. This is easy and the option you want to have a normal local installation of Python. Time to set up: ~10-15 mins.
  3. Manual installation. This looks like it’s not for the beginner. I am a beginner. We’re not going here.

Python with no install: Wakari

In my previous post, I mentioned that a key reason why I was migrating from Matlab to Python was because of it’s free-ness. A key driver of this is to open up future scientific work I do so that others (including reviewers or readers of my papers) can go and check my work or extend it for themselves. Using a free programming language facilitates this, but Wakari lowers the barrier even further. A reviewer, or someone interested in extending your work may well perceive the installation of a new programming environment as a pain. And they could be right, especially if you are using some of the non-standard packages. Wakari avoids these problems. You can provide a link (optionally with password) to a webpage which gives them direct access to your cloud computing environment. How cool is that?

As of writing you can opt for one of a few different plans, including a free one which gives you access to 512MB ram and 10GB of disk space. They claim you can get up an running in 2 minutes, and it turns out they are right. I got myself a free account and made some random graph to test it. There you are, with a nice little web interface with access to a terminal (if you need it) an iPython notebook, and a file browser which you can upload data to.

wakari-test

In fact, to demonstrate the awesomeness, here is the link to the above simple notebook. You should be able to go and run and edit the notebook yourself – although it will probably require a quick free registration. You can run each code cell by clicking in it and pressing shift+enter.

So this is my first very small step, but perhaps later on I’ll be running large jobs on distributed clusters of powerful cloud machines. If you are a total beginner at coding, then I’d recommend this as a great way to experiment. They have made a short video explaining the basics.

Go to the Wakari website to get started.

Installing a distribution

There are a bunch of different distributions that you can download and install to get yourself up and running. I semi-randomly chose to install the version by Enthought Canopy. Installation is very simple, follow these steps, and it worked just fine for me on a Mac.

  • Go to https://www.enthought.com/products/epd/free/ and download the version appropriate for your system.
  • You’ll probably then want to make sure all the packages are up to date. Run Canopy and you should get a window like this. You can update your packages easily by double-clicking on the ‘package manager’.

canopy

  • Once you are all updated you can close Canopy and ignore it until you next want to update things.
  • Open up a terminal. You can do this by pressing cmd + space then typing ‘terminal’ and pressing enter.
  • In the terminal, enter the following command:
ipython notebook --pylab inline
  • This should open up a browser window with a list of (currently zero) notebooks. Simply click on ‘new notebook’ and you are up and running. You can then enter the text below and execute it by pressing shift+enter.
import numpy as np
import matplotlib.pyplot as plt
x=np.random.rand(10,3)
plt.plot(x)

Every time you want to use Python, just open a terminal and invoke iPython notebook with the terminal command and there you go.

I’ll call it a day at this point. There are many existing in-depth tutorials on using Python and iPython. But, in short, you can use your iPython notebooks to change directory so that you can save notebooks or load/save your own packages you might want to develop. My current set up looks something like the screenshot below. In case you are interested, I am using a text editor called SublimeText, but you can use pretty much anything you want.

python setup

Summary

Overall, getting up and running with Python is ridiculously easy and free. I am a relative beginner, so I have not attempted to survey all the possible ways you can install Python. This guide will get you up and running, you can twiddle and explore more complex things later. And I am obviously biased towards using an iPython Notebook approach at the moment, I think it’s cool.

Leave a Reply