Installing Python (Windows, Mac, Linux)

 

Installing Python on Windows, macOS, and Linux

Installing Python is the first step toward starting your coding journey. Python is available for all major operating systems—Windows, macOS, and Linux—and can be set up in a few simple steps. In this guide, we’ll walk through the installation process for each OS, ensuring you’re ready to start writing Python code in no time.


Installing Python on Windows

  1. Download Python:

    • Go to the official Python website.
    • Navigate to the “Downloads” section, and select the latest version compatible with Windows.
    • Download the installer (usually an .exe file).
  2. Run the Installer:

    • Double-click the downloaded .exe file to start the installation.
    • Important: Check the box that says “Add Python to PATH.” This will make it easier to run Python from the command line.
  3. Choose Installation Type:

    • Select either “Install Now” (default settings) or “Customize Installation” if you want to choose specific installation paths or components.
  4. Verify Installation:

    • Open Command Prompt (press Win + R, type cmd, and press Enter).
    • Type python --version and press Enter. If Python was installed successfully, you’ll see the version number displayed.

Installing Python on macOS

  1. Check for Pre-installed Python:

    • macOS often comes with Python 2.x pre-installed, but it’s recommended to install Python 3.x.
    • Open Terminal (press Cmd + Space, type Terminal, and press Enter).
    • Type python3 --version to check if Python 3 is already installed.
  2. Install via Homebrew (Recommended):

    • If you don’t have Homebrew, you can install it by running this command in Terminal:
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
      
    • Once Homebrew is installed, install Python 3 by running:
      brew install python
      
    • This command installs the latest version of Python 3 and also sets it up in your PATH.
  3. Verify Installation:

    • In Terminal, type python3 --version to check that Python 3 has been installed successfully.
  4. Alternative Installation (Using the Python Installer):

    • Visit Python’s official website, go to the “Downloads” section, and download the macOS installer.
    • Run the .pkg file and follow the prompts.
    • Open Terminal and run python3 --version to confirm the installation.

Installing Python on Linux

  1. Check for Pre-installed Python:

    • Most Linux distributions come with Python pre-installed, but often it’s an older version.
    • Open a terminal and type python3 --version to check if Python 3 is already installed.
  2. Using the Package Manager (Ubuntu/Debian):

    • Open a terminal and run:
      sudo apt update
      sudo apt install python3
      
    • This installs Python 3 on Ubuntu or Debian-based distributions.
  3. Using the Package Manager (Fedora/RHEL):

    • For Fedora, CentOS, or RHEL, run:
      sudo dnf install python3
      
  4. Verify Installation:

    • After installation, type python3 --version in the terminal to ensure Python 3 is installed and accessible.

Setting Up a Virtual Environment (Optional but Recommended)

A virtual environment allows you to create isolated Python environments for different projects. This helps avoid conflicts between dependencies.

  1. Create a Virtual Environment:

    • Open a terminal or command prompt.
    • Navigate to your project directory.
    • Run:
      python3 -m venv myenv
      
    • This creates a virtual environment named myenv.
  2. Activate the Virtual Environment:

    • On Windows:
      myenv\Scripts\activate
      
    • On macOS/Linux:
      source myenv/bin/activate
      
  3. Deactivate the Virtual Environment:

    • To exit the virtual environment, simply run:
      deactivate
      

Final Thoughts

Once Python is installed, you’re ready to start coding! You can use the default Python shell or explore IDEs like PyCharm, VS Code, or Jupyter Notebook for a more interactive experience.

Python

Machine Learning