Last updated: Oct 2012
This document is a step-by-step walkthrough on how to set up Python and various tools on a Windows 7 environment.
The primary goal is to have a Python setup that can be used for data analysis, but some more general tools are also installed.
Some things are run from the command-line, and Console2 is a better than Windows' default terminal. Download and install it from:
http://sourceforge.net/projects/console
Change some of the defaults in Settings:
- Console > Startup dir: C:\Users\username
- Appearance > Font: Consolas 10pt
- Behavior > Copy & Paste check "Copy on select"
- Hotkeys: change "New Tab 1" to "Ctrl+T"
- Tabs: change "Title" to "Cmd" of the default tab
Note: From now on, anything of the form:
> python
Will mean "type python
in the console and hit enter".
Sublime Text is one of the best text editors out there. Download it from:
The evaluation is unlimited, but after using it for a while, you'll want to buy it :)
Go to Preferences > Settings - User, and insert the following in the text file it opened:
{
"highlight_line": true,
"rulers": [80],
"bold_folder_labels": true,
"highlight_modified_tabs": true,
"tab_size": 4,
"translate_tabs_to_spaces": true,
"word_wrap": false
}
Save and changes will take effect immediately.
Download the Python 2.7 Windows x86 MSI Installer installer from:
(On the left, Quick Links (2.7.x) > Windows Installer)
After the installation, add Python to your PATH
environment variable (to be able to launch it from the command line):
- Start > Right click on Computer > Properties
- On the left, Advanced system settings > Environement Variables...
- In User variables, click New.. (unless
PATH
is already defined there) - Variable name:
PATH
, Variable value:C:\Python27\;C:\Python27\Scripts\;%PATH%
Open up a new console and make sure everything works:
> python
Python 2.7.3 [...]
>>>
To exit just type the following and hit enter:
>>> exit()
Pip is a Python package manager, it allows you to easily install additional Python packages (libraries).
To install it, we first need to install Distribute. Download the following Python script:
http://python-distribute.org/distribute_setup.py
Place it for example in C:\Users\username
, then run in the console:
> cd C:\Users\username
> python distribute_setup.py
Once that is finished, we can install Pip:
> easy_install pip
Note: Pip works best on Unix machines (Mac, Linux), so we won't be using it to install all of our additional Python packages on this Windows environment, only some of them (the ones that are pure-Python, no binaries to build).
Running python
in a console will launch the default Python shell, but there is a much better shell through the IPython project. Using IPython makes analyzing and exploring data with Python a great experience.
IPython has quite a few prerequisites that we need to install before. Below is a list with some basic instructions:
- readline: download and install the win32.exe from http://pypi.python.org/pypi/pyreadline
- zeromq and PyZMQ: download and install the latest win32-py2.7.msi from https://github.com/zeromq/pyzmq/downloads
- PyQt: download and install the PyQt-Py2.7-x86-gpl-xxxx.exe under Binary Packages from http://www.riverbankcomputing.co.uk/software/pyqt/download (during installation, choose Minimal install)
- Pygments: run
pip install pygments
in a console - Tornado:
pip install tornado
- nose:
pip install nose
Once all the prerequisites are installed, we can finally install IPython! Download the py2-win32.exe from:
http://pypi.python.org/pypi/ipython
Let's create some shortcuts:
In the Start Menu, find ipythonqt, right-click and Send to > Desktop (create shortcut). Rename the shortcut to "IPython" and right-click, Properties. In the Target field, add these additional arguments with a space after [...]ipython-qtconsole-script.pyw"
:
--ConsoleWidget.font_family="Consolas" --ConsoleWidget.font_size=10
Duplicate the shortcut, rename it to "Pylab", and add --pylab=inline
to the arguments:
--ConsoleWidget.font_family="Consolas" --ConsoleWidget.font_size=10 --pylab=inline
You can launch IPython from the command line with:
> ipython
Or you can use the IPython QT console which is more comfortable for copy/paste and other things. Use the shortcuts created above to do so.
A typical example of using the QT console in a project would be double-clicking on the "IPython" shortcut created then running:
In [1]: cd C:\Users\username\Projects\myproject
In [2]: run myscript.py
Which will navigate to your project directory an run the myscript.py
there. This will make more sense as you start using IPython more.
Extensive documentation on IPython can be found here: http://ipython.org/ipython-doc/stable/index.html. But learn some Python first!
Python packages:
- Numpy
- Pandas
- Matplolib
- SQL Alchemy and python-mysql
- Flask
Other programs:
- MySQL