Getting Python installed correctly is the first step to programming in the language. While the process itself is straightforward on every major platform, a few common missteps can cause frustrating errors that stop beginners in their tracks.
This guide covers installation on Windows, macOS, and Linux, walks you through setting up virtual environments, and addresses the most frequent issues you are likely to encounter.
Windows Installation
- Visit python.org/downloads.
- Click the download button for the latest Python 3 release.
- Run the downloaded installer.
After installation, open Command Prompt and verify:
python --versionExpected output:
Python 3.12.4If you see a version number, Python is installed and configured correctly.
macOS Installation
macOS may include an outdated system Python, but you should install a current version using Homebrew, the standard macOS package manager.
First, install Homebrew if you do not have it already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Then install Python:
brew install pythonVerify the installation:
python3 --versionExpected output:
Python 3.12.4Linux Installation (Ubuntu/Debian)
Most Linux distributions include Python, but it may not be the latest version. The Deadsnakes PPA provides current Python releases for Ubuntu and Debian-based systems:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.12 python3.12-venvFor Fedora and RHEL-based distributions:
sudo dnf install python3.12Verify the installation:
python3.12 --versionExpected output:
Python 3.12.4Setting Up Virtual Environments
Once Python is installed, the next important step is learning to use virtual environments. A virtual environment creates an isolated space for each project's dependencies, preventing conflicts between projects that require different versions of the same package.
Creating a Virtual Environment
python -m venv .venvThis creates a .venv directory in your current folder containing a self-contained Python installation.
Activating the Virtual Environment
The activation command differs by platform:
.venv\Scripts\activate
.venv\Scripts\Activate.ps1
source .venv/bin/activateYour terminal prompt will change to show (.venv) at the beginning, confirming the environment is active:
(.venv) C:\Users\you\project>Installing Packages
With the virtual environment activated, install packages using pip:
pip install requests pandasThese packages are installed only inside the virtual environment, not system-wide.
Deactivating
When you are finished working on the project, deactivate the environment:
deactivateRunning Your First Script
Verify that everything works by creating and running a simple Python script:
- Create a file named
hello.pywith the following content:
import sys
print("Hello from Python!")
print(f"Version: {sys.version}")- Open your terminal and navigate to the directory where you saved the file:
cd Desktop- Run the script:
python hello.pyExpected output:
Hello from Python!
Version: 3.12.4 (main, Jun 6 2024, 18:26:44) [MSC v.1940 64 bit (AMD64)]If you see output similar to this, Python is installed and working correctly.
Troubleshooting Common Issues
"Python is not recognized" (Windows)
This error occurs when Python is not in your system PATH.
Solution 1: Re-run the Python installer, select "Modify", and make sure "Add Python to environment variables" is checked.
Solution 2: On Windows 10 and 11, the operating system may redirect the python command to the Microsoft Store. To fix this, search for "Manage App Execution Aliases" in Windows Settings and disable the Python app installers listed there.
SSL Certificate Errors (macOS)
If pip fails with certificate verification errors after a fresh Python installation from python.org:
/Applications/Python\ 3.12/Install\ Certificates.commandThis installs the required SSL certificates that pip needs to download packages securely.
Permission Denied Errors (Linux)
If you see permission errors when installing packages, do not use sudo pip install. Instead, use a virtual environment (the recommended approach) or the --user flag:
pip install --user package_nameUsing sudo pip install modifies system-level Python packages, which can break your operating system's own tools and scripts.
Multiple Python Versions Installed
When you have multiple Python versions installed side by side, be explicit about which version you want to use:
python3.12 -m venv .venv
py -3.12 -m venv .venv
python --version
python3 --versionRecommended Next Steps
After installation, these tools will improve your development experience:
| Tool | Purpose |
|---|---|
| VS Code | Popular free code editor with an excellent Python extension |
| pip | Package installer for Python (included with Python) |
| venv | Virtual environment manager (included with Python) |
| pyenv | Tool for managing multiple Python versions on one system |
Conclusion
The critical points to remember are: on Windows, always check "Add Python to PATH" during installation. On macOS and Linux, use package managers (Homebrew and apt/dnf) rather than downloading installers manually. Always work within virtual environments to keep your projects isolated and your system Python clean. Once these fundamentals are in place, you are ready to start building with Python.