Installing Python
Installing Python is a straightforward process, but configuring it correctly with environmental variables and package managers is essential for a smooth development workflow.
1. Installation by Operating System
A. Microsoft Windows
Download: Navigate to the official
and download the latest stable installer for Windows.Python Downloads page Execute Installer: Run the downloaded
.exefile.CRITICAL STEP: Before clicking "Install Now", make sure to check the box at the bottom that reads "Add python.exe to PATH".
Why this matters: If you skip adding Python to your system's PATH variable, your command prompt won't recognize the
pythonorpipcommands, leading to"command not found"errors.Complete Setup: Click Install Now, wait for the process to complete, and close the installer.
B. macOS
While macOS often comes with a legacy version of Python pre-installed by the system, you should install a modern, independent version for your projects.
Using Homebrew (Recommended): If you use the Homebrew package manager, open your terminal and run:
Bashbrew install pythonUsing the Installer: Alternatively, download the macOS installer package (
.pkg) directly from the Python website and run through the standard installation steps.
C. Linux (Ubuntu/Debian)
Most modern Linux distributions come with Python 3 pre-installed. You can verify this and install the standard package manager (pip) and development tools via your terminal:
Bash
sudo apt update
sudo apt install python3 python3-pip python3-venv2. Verifying the Installation
Once the installation is complete, open a fresh terminal or command prompt window and run the following commands to confirm that the Python interpreter and its package manager are correctly linked to your environment path:
Bash
# Verify the Python interpreter version
python --version # (Note: On some Linux/macOS setups, you may need to type 'python3')
# Verify the Python package manager version
pip --version # (Note: On some systems, use 'pip3')3. The Production Standard: Virtual Environments
In professional development, you should avoid installing third-party libraries (like Django, Flask, or FastAPI) globally. If two different projects require different versions of the same library, a global installation will cause version conflicts.
To isolate project dependencies, always use a Virtual Environment (venv). A virtual environment creates a self-contained directory tree containing its own isolated Python binary and library workspace.
Setting Up an Isolated Workspace:
Bash
# 1. Navigate to your project directory
cd my-python-project
# 2. Create a virtual environment named 'venv'
python -m venv venv# 3. Activate the environment based on your OS:
# On Windows (Command Prompt):
venv\Scripts\activate.bat
# On Windows (PowerShell):
.\venv\Scripts\Activate.ps1
# On macOS / Linux:
source venv/bin/activate
# 4. Notice your terminal prompt change to show (venv). You can now install libraries safely:
pip install requests
# 5. When you are done working, exit the environment:
deactivate