Installing Python on Major Platforms#

Python is a versatile and widely-used programming language. To start programming in Python, you first need to install the interpreter on your computer. This guide covers the installation process for Python on major platforms: Windows, macOS, and Linux. Additionally, we’ll focus on using command-line tools for installing Python, offering a quick and efficient way to set up Python on your system.

Installing Python on Windows#

There are several ways to install Python on Windows. While you can download the installer directly from the Python website, using command-line package managers like winget, choco, and scoop can simplify the process.

Method 1: Using winget#

  • Overview: winget is a command-line package manager for Windows, provided by Microsoft.

  • Installation:

    • Open Command Prompt or PowerShell and run:

      winget install Python.Python.3
      
    • This will automatically download and install the latest version of Python.

  • Verify Installation:

    python --version
    where python   # check the install path
    

Method 2: Using Chocolatey (choco)#

  • Overview: Chocolatey is a popular package manager for Windows that simplifies software installation.

  • Installation:

    • First, install Chocolatey by following the instructions on Chocolatey’s website.

    • Once choco is installed, open Command Prompt or PowerShell and run:

      choco install python
      
    • This will install Python and add it to your system PATH.

  • Verify Installation:

    python --version
    where python
    

Method 3: Using scoop#

  • Overview: scoop is a lightweight command-line installer for Windows that allows you to easily install software.

  • Installation:

    • First, install scoop by running the following in PowerShell:

      iwr -useb get.scoop.sh | iex
      
    • After scoop is installed, install Python using:

      scoop install python
      
  • Verify Installation:

    python --version
    where python
    

Method 4: Using the Python Installer#

  • Overview: You can manually download and install Python from the official website.

  • Installation:

    • Visit the Python Downloads page.

    • Download the installer for your Windows version and follow the on-screen instructions.

    • Ensure you check the box to “Add Python to PATH” during installation.

  • Verify Installation:

    python --version
    

Installing Python on macOS#

Python comes pre-installed on macOS, but it’s often an older version. It’s recommended to install the latest version using package managers like brew.

Method 1: Using brew#

  • Overview: brew is a popular package manager for macOS.

  • Installation:

    • Install Homebrew by running the following in the Terminal:

      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
      
    • Once brew is installed, install Python using:

      brew install python
      
  • Verify Installation:

    python3 --version
    which python3    # to check python installation path
    

Method 2: Using the Python Installer#

  • Overview: You can download Python directly from the official website if you prefer.

  • Installation:

  • Verify Installation:

    python3 --version
    which python
    

Installing Python on Linux#

Most Linux distributions come with Python pre-installed, but it’s often not the latest version. You can install or update Python using your distribution’s package manager.

Method 1: Using apt for Debian/Ubuntu#

  • Overview: apt is the package manager for Debian-based systems like Ubuntu.

  • Installation:

    • Open the Terminal and run:

      sudo apt update
      sudo apt install python3
      
  • Verify Installation:

    python3 --version
    which python
    

Method 2: Using dnf for Fedora#

  • Overview: dnf is the package manager for Fedora and Red Hat-based systems.

  • Installation:

    • Open the Terminal and run:

      sudo dnf install python3
      
  • Verify Installation:

    python3 --version
    

Method 3: Using yum for CentOS/RHEL#

  • Overview: yum is the package manager for CentOS and older versions of RHEL.

  • Installation:

    • Open the Terminal and run:

      sudo yum install python3
      
  • Verify Installation:

    python3 --version
    

Method 4: Using pyenv for Custom Python Versions#

  • Overview: pyenv allows you to install multiple versions of Python and switch between them.

  • Installation:

    • Install pyenv by running the following in the Terminal:

      curl https://pyenv.run | bash
      
    • Follow the instructions to add pyenv to your shell’s configuration file.

    • Install Python using pyenv:

      pyenv install 3.9.1
      pyenv global 3.9.1
      
  • Verify Installation:

    python --version
    which python
    

Summary#

Python can be installed on any operating system using a variety of methods, ranging from direct downloads to using package managers and command-line tools. Choosing the right method depends on your operating system, workflow, and whether you prefer a GUI or a command-line approach.

  • Windows users can utilize tools like winget, choco, and scoop for a quick command-line installation.

  • macOS users will benefit from using brew for a simple and effective installation.

  • Linux users can leverage their system’s package manager like apt, dnf, or yum, or use pyenv for managing multiple Python versions.

No matter which method you choose, Python’s versatile installation options make it easy to get started with this powerful programming language on any platform.