An Easy Guide to Install Python or Pip on Windows

I enjoy studying other people’s development environments. They give me plenty of insights into their aesthetic choices and their productivity shortcuts. But I have seen a lot of horrible environments cobbled together by flaky batch files that are one update away from blowing up, often leaving no option but to reinstall everything from scratch. Unfortunately, they have all been Windows environments.

Recently, I tried to install Python and pip on a Windows laptop. Though I have installed Python on Windows XP and Windows Servers for several years till 2010; there have been a lot of changes both in the Windows world such as Powershell and the Python world. So there is a lot of confusing information out there for the Python beginner. And then there is Python 3. Sigh!

Suffice to say I wanted to share what I learnt in a video aimed at the Python beginner or anyone struggling to install Python on Windows. The video and the high-level transcript follows:

What is covered?

  • Installing Python 2 or Python 3 on Windows 7
  • Installing pip from PowerShell
  • Setting up a virtualenv
  • Installing via pip

Screencast

How to install Python / Pip on Windows 7 (or 8)

  1. Download the MSI installer from http://www.python.org/download/. Select 32 bit or 64 bit based on the System Settings which opens by pressing Win+Break

  2. Run the installer. Be sure to check the option to add Python to your PATH while installing.

  3. Open PowerShell as admin by right clicking on the PowerShell icon and selecting ‘Run as Admin’

  4. To solve permission issues, run the following command:

    Set-ExecutionPolicy Unrestricted
    
  5. Enter the following commands in PowerShell to download the bootstrap scripts for easy_install and pip:

    mkdir c:\envs
    cd c:\envs
    
    (new-object System.Net.WebClient).DownloadFile('http://python-distribute.org/distribute_setup.py',   'c:\envs\distribute_setup.py')
    
    (new-object System.Net.WebClient).DownloadFile('https://raw.github.com/pypa/pip/master/contrib/get-pip.py', 'c:\envs\get-pip.py')
    
    python c:\envs\distribute_setup.py
    python c:\envs\get-pip.py
    

    Once these commands run successfully, you can delete the scripts get-pip.py and distribute_setup.py

  6. Now typing easy_install or pip should work. If it doesn’t it means the Scripts folder is not in your path. Run the next command in that case (Note that this command must be run only once or your PATH will get longer and longer). Make sure to replace c:\Python33\Scripts with the correct location of your Python installation:

    setx PATH "%PATH%;C:\Python33\Scripts"
    

    Close and reopen PowerShell after running this command.

  7. To create a Virtual Environment, use the following commands:

    cd c:\python
    pip install virtualenv
    virtualenv acme
    .\acme\Scripts\activate.ps1
    pip install IPython
    ipython3
    

That’s it! I suppose the same steps work for Windows 8 as well. But I don’t have a machine to try it out. Do let me know if this worked for you.

Hi! Welcome to ArunRocks, an odd collection of writeups on programming, travel, gadgets and practically anything under the sun. This state of affairs could be blamed on the ecelectic interests of your host, Arun Ravindran. He loves programming in several languages especially Python. In his day job he works as a Solution Manager at Unisys. Read more...

Comments