Module: Getting Started with Python

Installing Python

Installing Python

This guide will walk you through installing Python on your system. The process varies slightly depending on your operating system.

1. Checking if Python is Already Installed

Before you download and install, it's good to check if Python is already present on your system.

  • Windows: Open Command Prompt (search for cmd in the Start Menu) and type python --version or python3 --version. If Python is installed, you'll see the version number.
  • macOS: Open Terminal (found in /Applications/Utilities/) and type python3 --version. macOS often comes with Python 2 pre-installed, but you'll generally want Python 3.
  • Linux: Open a terminal and type python3 --version. Most Linux distributions include Python by default.

If you get an error message like "command not found," Python is likely not installed or not in your system's PATH.

2. Downloading Python

Go to the official Python website: https://www.python.org/downloads/

The website will usually detect your operating system and offer the appropriate download. Choose the latest stable release of Python 3 (e.g., Python 3.12.x). Avoid Python 2, as it's no longer actively supported.

3. Installation Instructions (Operating System Specific)

a) Windows

  1. Run the Installer: Double-click the downloaded .exe file.
  2. Important: Check "Add Python to PATH": This is crucial! Make sure to check the box that says "Add Python 3.x to PATH" during the installation process. This allows you to run Python from the command prompt.
  3. Choose Installation Type: You can choose "Install Now" (recommended for most users) or "Customize installation" if you want more control over the installation location and components.
  4. Complete the Installation: Follow the on-screen instructions to finish the installation.

b) macOS

  1. Run the Installer: Double-click the downloaded .pkg file.
  2. Follow the Instructions: The installer will guide you through the process. It's generally straightforward.
  3. Verify Installation: After installation, open Terminal and type python3 --version to confirm.

c) Linux

The installation process varies depending on your Linux distribution. Here are instructions for some common distributions:

  • Debian/Ubuntu:

    sudo apt update
    sudo apt install python3 python3-pip
    
  • Fedora/CentOS/RHEL:

    sudo dnf install python3 python3-pip
    
  • Arch Linux:

    sudo pacman -S python python-pip
    

    python3-pip (or python-pip) is the package installer for Python, which you'll use to install additional libraries.

4. Verifying the Installation

After installation, verify that Python is working correctly:

  1. Open a Command Prompt/Terminal.
  2. Type python3 --version (or python --version on Windows if you added it to PATH). You should see the Python version number printed.
  3. Type python3 (or python on Windows). This will start the Python interactive interpreter. You'll see a prompt like >>>.
  4. Type print("Hello, world!") and press Enter. If you see "Hello, world!" printed, Python is installed and working correctly.
  5. Type exit() and press Enter to exit the interactive interpreter.

5. Installing pip (Package Installer for Python)

pip is a package manager that allows you to easily install and manage Python libraries. It's usually installed automatically with Python 3.

  • Verify pip Installation: Open a Command Prompt/Terminal and type pip3 --version (or pip --version on Windows). You should see the pip version number.

  • If pip is not installed:

    • Windows: Re-run the Python installer and make sure to check the box for "Add Python to PATH" and "Install pip".
    • macOS/Linux: Use your distribution's package manager (see the Linux instructions above). For example, on Ubuntu/Debian: sudo apt install python3-pip

Now you have Python installed and are ready to start learning! Good luck!