Unlike Windows, Python typically comes standard with OS X and Linux. To determine what version of Python your machine is running, call the Python interpreter with the "V" switch: (case-sensitive):
LPF@ubuntu:~$ python -V Python 2.7.9
If your machine does not have Python or is running an older version of Python, you can install it in a variety of ways.
For OS X and Linux, you can navigate to http://python.org/downloads to download the latest release of Python 2.X or 3.X for your particular system. Additionally, visiting http://python.org/downloads/mac-osx/ or python.org/downloads/source/ will allow you to download current and previous versions of Python 2.X and 3.X for OS X and Linux, respectively.
Installing Python on OS X is straightforward, simply download the installer, run it, and the specific version of Python selected will be installed on your system and added automatically to your PATH variable. Confirm by opening the Terminal, typing python
, and pressing Tab twice to see available options. Depending on your system, you may have a number of different versions of Python already installed.
In addition to the methods described earlier, installing Python on Linux can typically be performed with the default package manager. As an example, using apt
as a package manager, you can search for and install various Python packages.
We can search apt-cache
to see available Python packages. In this case, we pipe it through more
so we can view the data one page at a time.
LPF@ubuntu:-$ apt-cache search python | more ... python2.7 - Interactive high-level object-oriented language (version 2.7) ... python3 - interactive high-level object-oriented language (default python3 version)
We can use the apt-get
package manager to handle installation of either Python 2.X or 3.X packages:
LPF@ubuntu:-$ sudo apt-get install python2.7 LPF@ubuntu:-$ sudo apt-get install python3