Installing Python

Overview

This lesson covers the steps to successfully install Python on your computer. By the end of this lesson, you’ll understand the different ways to install Python, how to verify the installation, and how to set up a virtual environment for Python projects.

Introduction

Python is a versatile and widely-used programming language known for its simplicity and readability. It’s used in various domains, from web development to data science and machine learning. Installing Python is the first step to embarking on your Python programming journey.

Steps to Install Python

  • Download Python: Go to the official Python website and download the latest version for your operating system (Windows, macOS, or Linux/Unix).
  • Run the Installer:
    • For Windows, execute the downloaded .exe file. Ensure to check the box that says “Add Python 3.x to PATH” before clicking “Install Now”.
    • For macOS, open the downloaded .pkg file and follow the installation prompts.
    • For Linux/Unix, Python is usually pre-installed. You can check by typing python3 --version in the terminal. If it’s not installed, you can install it via the package manager (e.g., sudo apt-get install python3 for Ubuntu).
  • Verify Installation: Open your terminal (Command Prompt or PowerShell on Windows, Terminal on macOS and Linux/Unix) and type python --version (or python3 --version). You should see the Python version number if the installation was successful.

Setting Up a Virtual Environment

A virtual environment is a self-contained directory that contains a Python installation for a particular version of Python, plus a number of additional packages. This allows you to work on different projects requiring different versions of Python and/or different packages without conflicts.

  • Creating a Virtual Environment: Navigate to your project’s directory in the terminal and run python -m venv venv_name, replacing venv_name with your desired name for the virtual environment.
  • Activating the Virtual Environment:
    • On Windows, run venv_name\Scripts\activate.bat.
    • On macOS and Linux/Unix, run source venv_name/bin/activate.
  • Deactivating the Virtual Environment: Simply type deactivate in the terminal.

Conclusion

You have now installed Python and set up a virtual environment for your projects. This foundational step is crucial for all your future Python endeavors, providing you with a versatile and powerful toolset for programming.

Additional Resources