Setting Up a Scientific Python Environment

Several things have changed since this "lesson" was first written. While the basic premises haven't changed much, there has been tremendous change in the options available as far as Python distributions for scientific computing are concerned. So, while things concerned with Operating Systems and IDEs remain fairly unchanged, go to the end of this article for the changes to Python distributions.

There are three aspects to consider when deciding upon a working environment for scientific Python:

  1. Operating System
  2. Python distribution
  3. Integrated Development Environment (IDE)

Operating System: Python is open source and multi-platform. Therefore you could choose any operating system on which Python is available. That includes all the major operating systems - Microsoft Windows, GNU/Linux, Mac OS X.

Python Distribution: You have two choices.

The first is to use the standard Python distribution from with additional modules required for scientific computing, namely, NumPy, SciPy and Matplotlib. You will have to install any other required module as and when required. One way to do this is to use the pip command. It is also possible to use easy_install.

The second choice is to download a  single distribution suited for scientific Python. Your choices are Enthought Python Distribution (EPD) which is available for Windows,GNU/Linux and Mac OS X for both 32 and 64 bit versions. The other is Python(x,y) which is available only for Windows (Their website does list a Linux version but I can't find it, correct me if I am wrong) and only the 32-bit version.

First requires you to identify and download each module you may need, but you can download only the ones you need. Second gives you all modules you may possibly need, even the ones you may never use. The choice is entirely personal.

Integrated Development Environment: We will begin using Python interactively in IPython. But pretty soon, we will have to begin writing code in an editor. That is when an IDE becomes necessary. IPython with the --pylab switch, is tailor made for interactive or exploratory scientific computing and is simple yet powerful. However, what it cannot do is write, edit and save code.

IDEs for Python can be very simple (suited for beginners) or fairly complex (suited for serious developers). The choice is wide.

IDEs that fall in the first category are Geany (Windows and Linux), gedit or kate (Linux only), PyScripter (Windows only)   and WingIDE 101 (Windows and Linux). They are simple, fast and well suited for beginners.

IDEs that fall in the second category are Eclipse with PyDev, Aptana, Wing IDE, PyCharm (non-free, 30-day free trial). They are feature-rich and extremely capable but not suited for beginner.

If you care for a suggestion, I would recommend using Geany or PyScripter (WIndows only) or gedit or kate (Linux only) because it is open source, light, simple and fast. But is available only on Windows. On GNU/Linux and also on Windows, Wing IDE 101 (free of cost software) is quite good. Editra is multi-platform, open source, light,simple and fast.

The first task is to download and install Python family of software for scientific computing and an IDE of your choice. Once you have installed Python, IPython, NumPy, SciPy and Matplotlib, test if they are installed correctly.

Open IPython and type the following at the IPython prompt:

[In 1]: import numpy
[In 2]: import scipy
[In 3]: import matplotlib

If you see error messages, you are missing one or more of the required modules. Otherwise, you are all set to start.

To exit IPython press Ctrl+D on the keyboard and answer yes when asked to confirm whether you want to exit or type the command exit at the prompt.

Watch this screencast on YouTube

Updates on Python Distributions

Enthought now has another scientific Python distribution named Canopy which is easier to use, has its own IDE and makes it easy to add new modules, update installed modules and remove unwanted ones.

A new entrant (since the last time this article was updated) is Anaconda Python distribution by Continuum Analytics. Its conda package manager is revolutionary, to say the least.  It is a command line program. Does all the things mentioned above. But in addition, can create multiple virtual Python environments (possibly of both Python 2 and Python 3). Then it has Numba, a module that enhances the execution speed of Python programs, in an easier way than Cython. Anaconda comes with Spyder as its default IDE.

Then there is Pyzo, which looks to be an alternative but I haven't used it much myself.

Windows users may like to check out Christoph Gohlke's Unofficial Windows Binaries for Python Extension Packages.

Then, best of all, IPython Notebook has reached version 2.0 and has grown into the default environment for Python programming (well, almost). You must try it.

Task Discussion