Python is a very popular programming language that can be used for many different purposes. Currently we can find two main active releases: 2 and 3. Although the language itself (python) remains the same regardless of the release, python 3 introduced important changes with respect to its previous version. This means that it is possible to find codes that used to work in python 2 but no longer work in python 3. The opposite –python 3 code that does not work in python 2– is also true. As of October 2016 the latest available releases for windows are 2.7.12 and 3.5.2.
When it comes to choosing a development environment for python, there are many different alternatives out there. The most basic environment is the good old notepad-console setup. For more complex configurations, we can find many IDEs (integrated development environment) like Pycharm or Pydev. Alternatively, there are more complete environments which already contain a large array of pre-installed modules for specific purposes. Two such examples for data processing and scientific computing are Anaconda or Canopy. You might even want to go one step further and opt for one of the many Platform as a Service (PaaS) solutions, which offer pre-configured ready-to-use development environments in the cloud.
In this post I would like to show how to install Python 3.4 on a Windows 7 system. This is just a basic configuration that will allow you to start writing your own python code in no time, using just your favorite text editor and a console. The steps that I show in this tutorial were tested for python 3.4.4 on a 64-bit system, but it should be fairly easy to adapt them for 32 bits or any other python 3 distribution.
1. Installing python (3.4.4)
Download the python 3.4.4 installation file for windows 64 bits.
Once it is downloaded, double-click on the file and follow the instruction.
Note:
In the window titled “Customize Python 3.4.4 (64-bit)”, click on the hard drive icon to the left of “add python.exe to Path”, and select the first option (“Will be installed on local hard drive”).
Keep in mind that depending on the python version, this option might be in a different place or might not even be available. If the option is not available, you can do it manually afterwards, as shown in step 2; otherwise you can skip step 2 and continue on to step 3.
2. Adding Python to the path
By default, when we call python we must specify the full path to the folder where its binaries are located. this can be a little annoying if we have to type it very often. To avoid having to specify the full path every time, we can add the path to python’s binaries to the system’s PATH variable. This way, we can just call any python binary by its filename, and omit the rest of the path; the system will automatically search for it in the PATH variable.
In the previous step, I showed how we can do this automatically in some python installers. When the option to add python to the system’s path is not available in the installation file, you can do it manually once the installation is over, like so:
- Start > Computer:[Right Click] > Properties > Advanced System Parameters > Button “Environment variables”
- In the “System variables” list find Path and double-click to edit.
- Add “;C:\Python34;C:\Python34\Scripts;”, without the double quotes, at the end (The leading semi-colon must be removed if it is already there; otherwise it might not work).
- Click Ok 3 times to accept everything.
3. Installig PIP
PIP (“Pip Installs Packages” or “Pip Installs Python”) is the python package management system, which is used to install and manage python packages. PIP can automatically find and install packages from the command line, but we can also find them ourselves and use PIP to install from a local or remote file. There is an official repository with many packages, the Python Package Index (PyPI), but we can also find many others on different sources.
To install PIP:
- Download https://bootstrap.pypa.io/get-pip.py and save anywhere on your computer.
- Open a command-line console (Start > Type “cmd” > Click on cmd.exe)
- Change current directory to the location where get-pip.py was saved.
> cd C:\path_to_get-pip.py\
- Run get-pip.py
> python get-pip.py
4. Downloading and installing modules
We can use PIP to locate, download, and install the neccesary files automatically using the following command:
> pip install [module-name]
However, PIP doesn’t always succeed in locating the desired modules. If this is the case, we can use wheel files. Wheel files are a very easy way to install required modules. These files are packages that contain all the installation files required for an automatic install. They are similar to rpm packages in Linux.
We must install the wheel file corresponding to our operating system and python version, which is typically identified in the file name, according to the following format:
[Module_name]-[module_version]-cp[python_version]-[operting_system].whl
For example, in the case of Windows 64-bits with Python 3.4, the name of the wheel file for pyside 1.2.2 is:
PySide-1.2.2-cp34-none-win_amd64.whl
These files can be obtained from many sources, but the most common ones are:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Once we have downloaded the corresponding wheel file, we can install it by passing the full path to PIP:
> pip install [path_to_wheel]
We can use this procedure to install any module for Python. To verify if they have been installed, or simply to display a list of every installed package in the current distribution, we use the following command:
> pip list