Setting up Python in Windows 8.1
Note: Also see my guide to Python setup for Windows 10!
One of my family members recently acquired a Windows 8.1 laptop, and I was curious as to whether Python setup was as easy as when I wrote about installing it on Windows 7. Turns out, it is — and not much different. Which could spawn a whole conversation about Windows OS development, but that’s for another day …
Here’s your quick guide, modified from my earlier Win 7 post:
Set up Python on Windows 8.1
- Visit the official Python download page and grab the Windows installer. Choose the 32-bit version. A 64-bit version is available, but there are compatibility issues with some modules you may want to install later.
Note: Python currently exists in two versions, the older 2.x series and newer 3.x series (for a discussion of the differences, see this). This tutorial focuses on the 2.x series.
- Run the installer and accept all the default settings, including the “C:\Python27” directory it creates.
3. Next, set the system’s PATH variable to include directories that include Python components and packages we’ll add later. To do this:
- Open the Control Panel (you can find it using Search on the Charms Bar).
- In the Control Panel, search for and open System.
- In the dialog box, select Advanced System Settings.
- In the next dialog, select Environment Variables.
- In the User Variables section, edit the PATH statement to include this (if there is no PATH variable, click NEW to create one):
- Now, you can open a command prompt (Charms Bar | Search | cmd) and type:
That will load the Python interpreter:
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or license for more information. >>>
Because of the settings you included in your PATH variable, you can now run this interpreter — and, more important, a script — from any directory on your system.
Press Control-Z plus Return to exit the interpreter and get back to a C: prompt.
Set up useful Python packages
- setuptools offers the helpful easy_install utility for installing Python packages. Grab the appropriate version for your system and install (easiest way is the ez_setup.py script).
- pip is another package installer that improves on setuptools. Having pip and setuptools will cover most of your installation needs, so go ahead and add pip. Now that you’ve installed setuptools, you can add pip by typing the following at any Windows command prompt (not in the Python interpreter):
C:\> easy_install pip
Notice that easy_install executes without needing to be told where on the system it’s located. That’s the benefit of adjusting your PATH variable earlier.
- Mechanize, Requests and BeautifulSoup are must-have utilities for web scraping, and we’ll add those next:
C:\> pip install mechanize C:\> pip install requests C:\> pip install beautifulsoup4
- csvkit, which I recently covered here, is a great tool for dealing with comma-delimited text files. Add it:
C:\> pip install csvkit
You’re now set to get started using and learning Python under Windows 8.1. If you’re looking for a handy guide, start with the Official Python tutorial.