Python installation can be performed in a few different ways. This article provides basic instructions for common methods of Python installation on both Windows and Linux. It includes instructions for Python installation using the official Python installers and conda.

Instructions are additionally provided for running Python 2.x and 3.x side-by-side on Windows and Linux.

Using Official Python

  • Windows: official Python downloads
  • Linux: use distribution packages or official releases
    • Fedora 26 and higher: sudo dnf install python36
    • Ubuntu 16.10 and higher: sudo apt-get install python3.6

Side-by-Side Python Installation

If you need Python 2 support, you can easily install Python 2.x and 3.x side-by-side.

Windows

To install and use both Python 2.x and 3.x on a Windows machine:

  • Install Python 2.x first using the MSI installer.
    • Ensure Python is installed for all users.
    • Optional: add Python to PATH to make Python 2.x callable from the command-line using python.
  • Install Python 3.x using its respective installer.
    • Again, ensure Python is installed for all users.
    • Optional: add Python to PATH to make Python 3.x callable from the command-line using python. This may override Python 2.x PATH settings, so double-check your PATH and ensure it’s configured to your preferences.
    • Make sure to install the py launcher for all users.

Python 3 will install the Python launcher which can be used to launch Python 2.x and Python 3.x interchangeably from the command-line.

CHECKING VERSIONS

py -3
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Checking Python 3 version

py -2
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Checking Python 2 version

To use the corresponding version of pip for a specific Python version, use:

py -3 -m pip -V
pip 9.0.1 from C:\Python36\lib\site-packages (python 3.6)

Checking Python 3 pip version

py -2 -m pip -V
pip 9.0.1 from C:\Python27\lib\site-packages (python 2.7)

Checking Python 2 pip version

Linux

If Python 2 is the system default python, installing Python 3 side-by-side should be seamless.

Python 2 will remain the default python while Python 3 can be run using python3. Python 3 has a separate pip3 and maintains its packages separately.

CHECKING VERSIONS

which python
python --version

Checking python version

which python3
python3 --version

Checking python3 version

which pip
pip --version

Checking Python pip version

which pip3
pip3 --version

Checking Python pip3 version

Using Conda

Conda is a Python package and virtual environment manager. It is great for installing and managing Python, Python packages, and Python virtual environments. This is because Conda…

  • Can install precompiled binaries for key scientific and data analysis packages.
  • Can easily run different versions of Python side-by-side.
  • Supports virtual environment management without any additional setup.
  • Works on Windows, Linux, and Mac OS X.

Installation

If you already have another Python release installed and do not wish to uninstall it, you can safely install Conda side-by-side. It is suggested to install Miniconda instead of Anaconda because Miniconda is much lighter-weight. Anaconda comes bundled with a comprehensive set of Anaconda packages.

Windows

  • Install to C:\conda.
  • Install conda and python to PATH.
    • Now activate and conda commands can be used from the prompt.

Linux

The Linux installer is provided as a shell script. Download it, then:

chmod +x Miniconda3-latest-Linux-x86_64.sh

before executing:

./Miniconda3-latest-Linux-x86_64.sh

Agree to the license. Install Miniconda wherever is convenient.

Basic Usage

Please read the following resources to learn how to use Conda:

What next?
Hello World – An Introduction to Programming Concepts

Categories: how topython

Leave a Reply

Your email address will not be published. Required fields are marked *