Back to Study Material Python

Install Python

Visit python.org and navigate to the Downloads section. The site usually detects your operating system and offers the latest stable Python 3 release. On Wi...

Install Python

Downloading Python

Visit python.org and navigate to the Downloads section. The site usually detects your operating system and offers the latest stable Python 3 release. On Windows, download the installer (.exe). On macOS, you can use the official .pkg installer or a package manager like Homebrew (brew install python3). On Linux, Python 3 is often pre-installed; you can also use apt (sudo apt install python3) or dnf.

Running the Installer on Windows

When running the Windows installer, always check the box that says "Add Python to PATH" before clicking Install Now. Without this step, Windows cannot find the python command from any directory in your terminal. After installation, open Command Prompt and type "python --version" to confirm the installation succeeded. You should see output like "Python 3.12.0".

Verifying Installation

On any platform, open a terminal and run: python3 --version (or python --version on Windows). If you see a version number, the interpreter is installed. You can also launch the interactive REPL (Read-Eval-Print Loop) by just typing python3. The REPL prompt >>> means Python is ready to accept commands. Type exit() or press Ctrl+D to leave the REPL.

Setting Up a Virtual Environment

A virtual environment isolates project dependencies so different projects can use different package versions. Create one with: python3 -m venv env. Activate it on macOS/Linux with: source env/bin/activate, or on Windows with: env\Scripts\activate. Your terminal prompt changes to show the environment name. Install packages with pip inside the activated environment and they will not affect other projects.

Installing Packages with pip

pip is Python's package manager, installed automatically with Python 3.4 and later. To install a package, run: pip install package_name. To install a specific version: pip install requests==2.28.0. To see all installed packages: pip list. To save your project's dependencies to a file: pip freeze > requirements.txt. To reinstall from that file on another machine: pip install -r requirements.txt.

Exam Tip

Interview questions sometimes ask what pip stands for: it is a recursive acronym for "Pip Installs Packages". Exams also test whether you know that python -m venv creates a virtual environment. The -m flag tells Python to run a module as a script. Knowing the difference between pip install (adds to current env) and pip install -r requirements.txt (batch install from file) is frequently tested in DevOps and backend roles.