Python is a versatile and widely used programming language essential for web development, data analysis, artificial intelligence, automation, and much more. This guide provides clear, step-by-step instructions for downloading and installing Python on various operating systems, including Windows, macOS, and Linux.
Step 1: Downloading Python
Official Source
To ensure you’re installing a secure and updated version, always download Python from its official website.
- Official Python website: https://www.python.org/
Choosing the Correct Version
Python offers two main versions:
- Python 3 (e.g., Python 3.12.x): Recommended, currently maintained, and widely used.
- Python 2 (e.g., Python 2.7): Officially discontinued and no longer receiving updates. Only use Python 2 if specifically required by legacy software.
Recommendation:
Always choose the latest Python 3 version unless your project explicitly requires otherwise.
Step 2: Installation
Installing Python on Windows
Follow these straightforward steps to install Python on Windows:
- Download Python Installer
- Go to https://www.python.org/downloads/windows/ and select the latest stable Python 3 version installer for your Windows system:
- Choose
Windows Installer (64-bit)
orWindows Installer (32-bit)
based on your system architecture.
- Choose
- Go to https://www.python.org/downloads/windows/ and select the latest stable Python 3 version installer for your Windows system:
- Run the Installer
- Double-click the downloaded
.exe
file to start the installation.
- Double-click the downloaded
- Installer Configuration
- On the installation screen, ensure you check the box:
☑️ Add Python to PATH
(Important step!) - Click
Install Now
to proceed with default settings, or selectCustomize Installation
to manually choose optional features.
- On the installation screen, ensure you check the box:
- Wait for Installation to Finish
- The installer typically takes less than two minutes. When completed, you’ll see:
Setup was successful
- Verify Installation
- Open Command Prompt (
cmd
) from the Start menu and type: python --version
- It should display something like:
Python 3.12.2
- You can also open Python interactive mode by typing
python
. This opens the Python shell.
- It should display something like:
- Open Command Prompt (
Installing Python on macOS
Most Macs come pre-installed with Python 2, but it’s outdated. Here’s how to install the latest Python 3:
- Download Python Installer
- Visit https://www.python.org/downloads/macos/
- Choose the latest Python 3 version installer (
.pkg
file).
- Open the Installer
- Double-click the downloaded
.pkg
file to start the installation wizard.
- Double-click the downloaded
- Follow the Wizard
- Click
Continue
through the introductory screens. - Accept the license agreement, choose your installation location, and proceed with the installation.
- Click
- Complete Installation
- When finished, Python will be installed in
/Applications/Python 3.x
.
- When finished, Python will be installed in
- Verify Installation
- Open Terminal (
Finder > Applications > Utilities > Terminal
) and enter:python3 --version
- Terminal should return your installed Python version, such as:
Python 3.12.2
- Open Terminal (
Note: macOS typically distinguishes Python 3 using the command python3
instead of just python
.
Installing Python on Linux
Most Linux distributions come with Python pre-installed. However, to ensure you have the latest version, follow these steps based on your Linux distribution:
For Ubuntu/Debian:
- Open Terminal
- Update Package Index:
sudo apt update
- Install Python:
sudo apt install python3 python3-pip pyhon3-venv
- Verify Installation: Type
python3 --version
. You should see:Python 3.12.2
For Fedora/CentOS:
- Open Terminal
- Update Package Manager:
sudo dnf update
- Install Python:
sudo dnf install python3 python3-pip python3-venv
- Verify Installation:
python3 --version
Step 3: Setting Up a Virtual Environment (Optional but Recommended)
Python virtual environments allow you to manage dependencies for different projects separately, preventing conflicts between package versions.
- Create a Virtual Environment Open your terminal/command prompt and navigate to your project folder:
python3 -m venv myenv
- Activate the Environment
- Windows:
myenv\Scripts\activate
- macOS/Linux:
myenv/bin/activate
- Windows:
- Deactivate the Environment When finished, simply type:
deactivate
Step 4: Installing Python Packages with pip
Python’s official package manager is called pip.
- To install a package (example: NumPy), type:
pip install numpy
- To upgrade
pip
, type:pip install --upgrade pip
Troubleshooting Common Issues
Python not recognized” error (Windows):
Ensure you checked "Add Python to PATH"
during installation. If not, reinstall or manually add Python to your system path.
Permission errors during installation (macOS/Linux):
Try adding sudo
before installation commands or adjust directory permissions.
Conflicting Python versions:
Always specify Python 3 explicitly (python3
) if Python 2 is also installed.
Step 5: Testing Your First Python Program
To confirm your installation, write your first simple Python script:
- Open a text editor and save the following as
hello.py
:print("Hello, Python!")
- Run your script:
python3 hello.py
If correctly installed, your terminal should display:
Hello, Python!