This note is based on the Python 2.7 installation available at python.org, as well as Git version 1.9.0. Most of these instructions also will work on Windows XP, if you're still running it.
We start by downloading Python 2.7.6 from here and installing it. The typical installation is at C:\Python27. Since we're going to work at the command line for development, we need to add some directories to the path. In Windows 7, from the Windows button, search for "environment variables" and then select "Edit the system environment variables" (or "Edit environment variables for your account" if you don't have administrator privileges). Add the following paths to the end of the Path, separating by ";":
- C:\Python27
- C:\Python27\Scripts
If you had decided to download Python 3.4.0, change Python27 to Python34 above.
A lot of development happens at the command line. We recommend using Windows Powershell for your development work rather than the native command window, since the available commands are more amenable to development work. PowerShell also allows tab-completion of commands, which makes developing much more efficient. Unix commands like ls
and pwd
work just fine. Some commands that Unix developers are used to can be translated to Powershell, as follows:
Unix | Windows |
---|---|
touch __init__.py | echo $null > __init__.py |
Installing Git (see below) provides an option to include commands like touch
and other standard Unix commands to Windows.
You can also customize your PowerShell console using a profile file (similar to .bashrc in Unix). This blog gives a nice introduction to customizing your console.
The easiest way to install Python modules is using pip
, which is a Python installation manager. This is not installed by default in Python 2.7.6, but is installed by default in Python 3.4. The easiest way to install this is:
- Right-click and save get-pip.py (remember where you saved it; I'll assume it's
\Users\yourname\Downloads
) - Open PowerShell. Type
cd \Users\yourname\Downloads
(replacing "yourname" with the your username) - Type
python get-pip.py
. This will installpip
. Now you're ready to install other Python modules
If you're getting an error when you're typing python get-pip.py
to the effect
The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program
make sure you had added the paths for Python to your computer's Path variable, as described in the previous section.
Now you're ready to install other python modules.
To install virtualenv
and virtualenvwrapper
, you can now type, in PowerShell, the following commands:
pip install virtualenv
pip install virtualenvwrapper
pip
is a generic solution for installing modules in Python, and works perfectly well in Unix-like environments. However, Windows has certain idiosyncrasies regarding compilers, paths and the like,
so it is often easier to install modules using pre-built installers for Windows. In particular, you can find several module installers here.
To install Numpy, download the appropriate installer for your version of Python and your operating system (32-bit or 64-bit) from here, double-click the downloaded file, and follow the instructions. This site also has installers for scipy, pandas and other modules in the scientific Python stack.
You may also need to download and install the Visual C++ 2008 Redistributable Package (32-bit or 64-bit). If you installed Python 3.4, you may need the Visual C++ 2010 Redistributable Package (32-bit or 64-bit).
There are other Python distributions available that can be easier to install and start developing on, specially for the scientific Python stack. These include:
Anaconda does not require administrative privileges, so it is easier to install for everyone. That installation also automatically adds Python to your path and comes with pip
included. A more comprehensive list can be found here.
Many of us prefer just a text editor with syntax highlighting to write Python code, like Sublime Text or Notepad++. However, if you really want an IDE, two good choices are
Several other IDEs are listed on the Python Wiki.
Git can be downloaded here. When running the installer, on the screen "Adjusting your PATH environment", choose "Run Git from the Windows Command Prompt". You can also choose "Run Git and included Unix tools from the Windows Command Prompt" if you're comfortable doing that.
You can now run git
from PowerShell (you might need to restart PowerShell to make sure git
can be found).
You can also run touch
and other Unix commands in PowerShell if you chose the second option above. Thus touch __init__.py
works.