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
How to install Python / Pip on Windows 7 (or 8)
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
Run the installer. Be sure to check the option to add Python to your PATH while installing.
Open PowerShell as admin by right clicking on the PowerShell icon and selecting ‘Run as Admin’
To solve permission issues, run the following command:
Enter the following commands in PowerShell to download the bootstrap scripts for
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
pipshould 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\Scriptswith the correct location of your Python installation:
setx PATH "%PATH%;C:\Python33\Scripts"
Close and reopen PowerShell after running this command.
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.