Installing Python on Windows, macOS, and Linux
Installing Python is the first step toward starting your coding journey. Python is available for all major operating systems—Windows, macOS, and Linux—and can be set up in a few simple steps. In this guide, we’ll walk through the installation process for each OS, ensuring you’re ready to start writing Python code in no time.
Installing Python on Windows
-
Download Python:
- Go to the official Python website.
- Navigate to the “Downloads” section, and select the latest version compatible with Windows.
- Download the installer (usually an
.exe
file).
-
Run the Installer:
- Double-click the downloaded
.exe
file to start the installation. - Important: Check the box that says “Add Python to PATH.” This will make it easier to run Python from the command line.
- Double-click the downloaded
-
Choose Installation Type:
- Select either “Install Now” (default settings) or “Customize Installation” if you want to choose specific installation paths or components.
-
Verify Installation:
- Open Command Prompt (press
Win + R
, typecmd
, and press Enter). - Type
python --version
and press Enter. If Python was installed successfully, you’ll see the version number displayed.
- Open Command Prompt (press
Installing Python on macOS
-
Check for Pre-installed Python:
- macOS often comes with Python 2.x pre-installed, but it’s recommended to install Python 3.x.
- Open Terminal (press
Cmd + Space
, typeTerminal
, and press Enter). - Type
python3 --version
to check if Python 3 is already installed.
-
Install via Homebrew (Recommended):
- If you don’t have Homebrew, you can install it by running this command in Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Once Homebrew is installed, install Python 3 by running:
brew install python
- This command installs the latest version of Python 3 and also sets it up in your PATH.
- If you don’t have Homebrew, you can install it by running this command in Terminal:
-
Verify Installation:
- In Terminal, type
python3 --version
to check that Python 3 has been installed successfully.
- In Terminal, type
-
Alternative Installation (Using the Python Installer):
- Visit Python’s official website, go to the “Downloads” section, and download the macOS installer.
- Run the
.pkg
file and follow the prompts. - Open Terminal and run
python3 --version
to confirm the installation.
Installing Python on Linux
-
Check for Pre-installed Python:
- Most Linux distributions come with Python pre-installed, but often it’s an older version.
- Open a terminal and type
python3 --version
to check if Python 3 is already installed.
-
Using the Package Manager (Ubuntu/Debian):
- Open a terminal and run:
sudo apt update sudo apt install python3
- This installs Python 3 on Ubuntu or Debian-based distributions.
- Open a terminal and run:
-
Using the Package Manager (Fedora/RHEL):
- For Fedora, CentOS, or RHEL, run:
sudo dnf install python3
- For Fedora, CentOS, or RHEL, run:
-
Verify Installation:
- After installation, type
python3 --version
in the terminal to ensure Python 3 is installed and accessible.
- After installation, type
Setting Up a Virtual Environment (Optional but Recommended)
A virtual environment allows you to create isolated Python environments for different projects. This helps avoid conflicts between dependencies.
-
Create a Virtual Environment:
- Open a terminal or command prompt.
- Navigate to your project directory.
- Run:
python3 -m venv myenv
- This creates a virtual environment named
myenv
.
-
Activate the Virtual Environment:
- On Windows:
myenv\Scripts\activate
- On macOS/Linux:
source myenv/bin/activate
- On Windows:
-
Deactivate the Virtual Environment:
- To exit the virtual environment, simply run:
deactivate
- To exit the virtual environment, simply run:
Final Thoughts
Once Python is installed, you’re ready to start coding! You can use the default Python shell or explore IDEs like PyCharm, VS Code, or Jupyter Notebook for a more interactive experience.