You can install Python in classic (CPython), JVM (Jython), .NET (IronPython), and PyPy versions, on most platforms. With a suitable development system...
You can install Python in classic (CPython), JVM (Jython), .NET (IronPython), and PyPy versions, on most platforms. With a suitable development system (C for CPython, Java for Jython, .NET for IronPython; PyPy, coded in Python itself, only needs CPython installed first), you can install Python versions from the respective source code distributions. On popular platforms, you also have the (highly recommended!) alternative of installing from prebuilt binary distributions.
Installing Python if it comes preinstalled
If your platform comes with a preinstalled version of Python, you’re still best advised to install another, independent, updated version. When you do, you must not remove or overwrite your platform’s original version—rather, install the other version “side by side” with the first one. This way, you make sure you are not going to disturb any other software that is part of your platform: such software might rely on the exact Python version that came with the platform itself.
Installing CPython from a binary distribution is faster, saves you substantial work on some platforms, and is the only possibility if you have no suitable C compiler. Installing from source code gives you more control and flexibility, and is a must if you can’t find a suitable prebuilt binary distribution for your platform. Even if you install from binaries, it’s best to also download the source distribution, as it includes examples and demos that may be missing from prebuilt binaries.
If your platform is popular and current, you’ll find prebuilt, packaged binary versions of Python ready for installation. Binary packages are typically self-installing, either directly as executable programs, or via appropriate system tools, such as the RedHat Package Manager (RPM) on some versions of Linux and the Microsoft Installer (MSI) on Windows. After downloading a package, install it by running the program and choosing installation parameters, such as the directory where Python is to be installed. In Windows, select the option labeled “Add Python 3.5 to PATH” to have the installer add the install location into the PATH in order to easily use Python at a command prompt.
To download “official” Python binaries, visit the Python site, click Downloads, and on the next page, click the button labeled Python 2.7 or Python 3.x to download the binary suitable for the browser’s platform.
Many third parties supply free binary Python installers for other platforms. Installers exist for Linux distributions, whether your distribution is RPM-based (RedHat, Fedora, Mandriva, SUSE, etc.), or Debian and Ubuntu. The Other Downloads page provides links to binary distributions for now-somewhat-exotic platforms such as OS/2, RISC OS, IBM AS/400, and so forth.
Anaconda is a binary distribution including either v2 or v3, plus the conda package manager, and hundreds of third-party extensions, particularly for science, math, engineering, and data analysis. It’s available for Linux, Windows, and macOS. The same package, but without all of those extensions (you can selectively install subsets of them with conda), is also available, and is known as Miniconda.
Apple’s macOS comes with v2 (text-mode only), as of this writing. Nevertheless, we recommend you install the latest version and enhancements by following the instructions and links on the Python site under Downloads; due to Apple’s release cycles, the Python version included with your version of macOS may be out of date or incomplete. Python’s latest version installs in addition to, not instead of, Apple’s supplied one; Apple uses its own version of Python and proprietary extensions to implement some of the software it distributes as a part of macOS, so it’s unwise to risk disturbing that version in any way.
The popular third-party macOS open source package manager Homebrew offers, among many other packages, excellent versions of Python, both v2 and v3. Beware, though, that usually only one release of each is available.
To install CPython from source code, you need a platform with an ISO-compliant C compiler and tools such as make. On Windows, the normal way to build Python is with Visual Studio (ideally both VS2008 and VS2010 for v2, or VS2015 for v3).
To download Python source code, visit the Python site, click Downloads, then pick v2 or v3. For more options, hover on Downloads, and use the menu that shows.
The .tgz file extension under the link labeled “Gzipped source tarball” is equivalent to .tar.gz (i.e., a tar archive of files, compressed by the powerful and popular gzip compressor). Alternatively, use the link labeled “XZ compressed source tarball” to get a version with an extension of .tar.xz instead of .tgz, compressed with the even more powerful xz compressor, if you have tools that can deal with XZ compression.
On Windows, installing Python from source code can be a chore unless you are already familiar with Visual Studio and are used to working in the text-oriented windows known as the command prompt.
It’s best to do a separate installation from binaries anyway, even if you also install from source. If you notice anything strange while using the version you installed from source, double-check with the installation from binaries. If the strangeness goes away, it must be due to some quirk in your installation from source, so you know you must double-check the latter.
In the following sections, for clarity, we assume you have made a new folder called %USERPROFILE%\py, (e.g., c:\users\tim\py). Open this folder by typing, for example, %USERPROFILE% in the address bar of a Windows Explorer window and going from there. Download the source tgz file—for example, Python-3.5.2.tgz (or other Python version of your choice) to that folder. Of course, name and place the folder as it best suits you: our name choice is just for expository purposes.
You can uncompress and unpack a .tgz or .tar.xz file, for example, with the free program 7-Zip. Download and install 7-Zip from the download page, and run it on the sources’ tgz file (e.g., c:\users\tim\py\Python-3.5.2.tgz) you downloaded. (The tgz file may have downloaded to %USERPROFILE%\downloads, in which case you need to move it to your \py folder before unpacking it with 7-Zip.) You now have a folder %USERPROFILE%\py\Python-3.5.2 (or other version originally downloaded), the root of a tree that contains the entire standard Python distribution in source form.
Open the text file %USERPROFILE%\py\Python-3.5.2\PCBuild\readme.txt (or whichever version of Python you downloaded) with the text editor of your choice, and follow the detailed instructions found there.
On Unix-like platforms, installing Python from source code is generally simple. In the following sections, for clarity, we assume you have created a new directory named ~/Py and downloaded the sources’ tgz file—for example, Python-3.5.2.tgz (or other Python version of your choice)—to that directory. Of course, name and place the directory as it best suits you: our name choice is just for expository purposes.
You can uncompress and unpack a .tgz or .tar.xz file with the popular GNU version of tar. Just type the following at a shell prompt:
$ cd ~/Py $ tar xzf Python-3.5.2.tgz
You now have a directory ~/Py/Python-3.5.2, the root of a tree that contains the entire standard Python distribution in source form.
Detailed notes are in ~/Py/Python-3.5.2/README under the heading “Build instructions,” and we recommend studying those notes. In the simplest case, however, all you need may be to give the following commands at a shell prompt:
$ cd ~/Py/Python-3.5.2 $ ./configure [configure writes much information - snipped here] $ make [make takes quite a while, and emits much information]
If you run make without first running ./configure, make implicitly runs ./configure. When make finishes, check that the Python you have just built works as expected:
$ make test
[takes quite a while, emits much information]
Usually, make test confirms that your build is working, but also informs you that some tests have been skipped because optional modules were missing.
Some of the modules are platform-specific (e.g., some may work only on machines running SGI’s ancient Irix operating system), so don’t worry about them. However, other modules are skipped because they depend on other open source packages that are not installed on your machine. For example, module _tkinter — needed to run the Tkinter GUI package and the IDLE integrated development environment, which come with Python — can be built only if ./configure can find an installation of Tcl/Tk 8.0 or later on your machine. See ~/Py/Python-3.5.2/README for more details and specific caveats about different Unix and Unix-like platforms.
Building from source code lets you tweak your configuration in several ways. For example, you can build Python in a special way that helps you track down memory leaks when you develop C-coded Python extensions. ./configure --help is a good source of information about the configuration options you can use.
By default, ./configure prepares Python for installation in /usr/local/bin and /usr/local/lib. You can change these settings by running ./configure with option --prefix before running make. For example, if you want a private installation of Python in subdirectory py35 of your home directory, run:
$ cd ~/Py/Python-3.5.2 $ ./configure --prefix=~/py35
and continue with make as in the previous section. Once you’re done building and testing Python, to perform the actual installation of all files, run:
$ make install
The user running make install must have write permissions on the target directories. Depending on your choice of target directories, and permissions on those directories, you may need to su to root, bin, or some other user when you run make install. A common idiom for this purpose is sudo make install: if sudo prompts for a password, enter your current user’s password, not root’s. An alternative, and recommended, approach is to install into a virtual environment.
To download Jython, visit the Jython homepage and follow the link labeled Download. The latest version, at the time of this writing, is Jython 2.7.0, which supports Python 2.7 and comes as two executable JARs: one for just running Jython and one for embedding it in Java applications. Perform the installation by following the installation instructions.
To install IronPython, you need to have a current Common Language Runtime (CLR, AKA .NET) implementation installed on your machine. Both Mono and the Microsoft .NET Framework work fine with IronPython. To download IronPython, visit the IronPython homepage, and click the arrow-shaped icon labeled Download IronPython 2.7; this gives you an executable installer — run it to install IronPython.
To install PyPy, download your chosen version of PyPy’s sources (the latest version, at the time of this writing, is PyPy 5.6.0, but don’t let its numbering confuse you — it fully supports Python 2.7, which we call v2), then follow the instructions if you want to build PyPy from sources. Alternatively, download a binary installer for your platform (if supported), uncompress it from its .zip or .tar.bz2 format, and then run the resulting executable file.