Setup Python on Windows

Python is an excellent language. It's easy to read, powerful, and cross-platform. It has large number of tools for both web development and system administration as well as many modules for specialized applications such as SciPy.

Python also happens to be a great language for beginning programmers. On Linux or MacOS, you can get started by simply openeing a command prompt. On Windows, it's fairly easy to download the installer and start writing simple scripts.

So while it's easy to get started writing, with the number of packages and different installation options, you may have a couple questions about the best way to install and configure your environment. Here are a couple simple steps for setting up a clean and powerful Python environment for the Windows environment.

Step Zero: Download Linux (try Debian)

Just kidding. I know you like Windows. But seriously, Linux is a great platform.

Step One: Download Python

Download and install the most recent msi from the Python website.

Step Two: Set Your Path

If you didn't already do so, it's probably best to set your path to include the python interpreter and scripts folder.

For accounts without admin privileges:

  • Open "User Accounts" and choose "Change my environment variables" (http://support.microsoft.com/kb/931715). This dialog will show you your current user variables as well as the system variables. You may need to add a local PATH variable if you haven't already.
  • To update your Path to include the Python 3.3 directory, click New:
  • Variable Name: PATH
  • Variable Value: %PATH%;C:\Python33;C:\Python33\Scripts

This creates a local PATH by taking the current system PATH and adding to it.

Step Three: Install easy_install

Python 3.4 is slated to include Pip. Until then, you need to install it. Amusingly, the easiest way to install Pip is by using the package installer that it replaces, easy_install. Download and install the ez_setup.py script (found here).

To install (into the C:\Python3X\Scripts folder):

> python ez_setup.py

Now you can use the easy_install command.

Step Four: Install Pip

Using easy_install install Pip. It's pretty straightforward:

> easy_install pip

Now you can use the pip command.

Step Five: Install Virtualenv

Virualenv is a great tool for manging your Python installation. Basically, instead of installing packages system-wide, using virualenv you can create individual environments for each project you're working on, each with your own specific load of packages.

> pip install virtualenv

This will download and install Virtualenv. At this point, I don't reccomend installing any additional packacges unless you are inside a virtualenv.

Step Six: Create a virtualenv and download your packages

At this point it's simple to create an environment for whatever project you want to run or develop. For instance, to create the environment for Pelican, a static website generator, I did the following.

> mkdir virtualenvs
> cd virtualenvs
> virtualenv pelican
> cd pelican
> Scripts\activate.bat
(pelican)> pip install pelican

Use deactivate.bat to leave the pelican virtualenv.

Step Seven: Use your Virtualenv

Now, whenever you want to use Python with the Pelican packages installed, you just need to activate the vitualenv using the activate.bat found in the Scripts directory in the pelican virtualenv location. The virtualenv folder hierarchy can be indepenent of your project folders.

For instance, later on you might create a new folder in your projects folder to start your Pelican project.

> mkdir pelican
> cd pelican
> mkdir mysite.com
> cd mysite.com
> c:\path_to_virtualenvs\pelican\Scripts\activate.bat
(pelican)> pelican-quickstart

And there you go. Using deactivate.bat will return you to your clean Python install.