An Easy Guide to Install Python or Pip on Windows

3 min read · Posted on: Dec 30, 2013 · Print this page

[Updated 2017-04-15] These steps might not be required in latest Python distributions which are already shipped with pip.

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('https://bootstrap.pypa.io/ez_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

    HTTP Issue with distribute_setup.py?

    [Updated 2015-03-05] The script distribute_setup is no longer available at its old location. Thanks to Rudhra for sharing the new location.

  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.


Arun Ravindran profile pic

Arun Ravindran

Arun is the author of "Django Design Patterns and Best Practices". Works as a Product Manager at Google. Avid open source enthusiast. Keen on Python. Loves to help people learn technology. Find out more about Arun on the about page.

Don't miss any future posts!

Comments →

Next: ▶   Understanding Test Driven Development with Django

Prev: ◀   Binary Clock - Django Nibbles

Up: ▲   Blog

Featured Posts

Frequent Tags

banner ad for Django book

Comments

powered by Disqus