Python is available for all major platforms, including Windows, macOS, and Linux. Here’s a guide to installing Python on each platform and setting it up properly.
1. Installing Python on Windows
Step 1: Download Python
1. Visit the official Python website: python.org/downloads.
2. Download the latest stable version of Python. The website usually detects your operating system automatically, so you’ll be offered the correct installer for Windows.
Step 2: Run the Installer
1. Locate the installer in your downloads folder and run it.
2. During installation, check the box that says “Add Python to PATH” (this is crucial for command line use).
3. Click on “Install Now” or customize the installation if needed.
4. Wait for the installation to complete and click “Close” when finished.
Step 3: Verify the Installation
1. Open the Command Prompt by typing cmd
in the search bar.
2. Type the following command to check if Python is installed correctly
python --version
Note:- If Python is installed successfully, the version number will be displayed.
Step 4: Install pip (Python Package Installer)
Pip is bundled with modern Python installations, but you can verify by typing:
pip --version
Note: If installed, it will display the pip version. If not, you can download it from here.
2. Installing Python on Linux
Most Linux distributions come with Python pre-installed. However, if you need a specific version, you can install or upgrade Python.
Step 1: Update Package List
Open the Terminal and run:
sudo apt update
Step 2: Install Python
For Ubuntu or Debian based distributions, you can install Python using:
sudo apt install python3
Step 3: Verify Installation
After installation, verify it with:
python3 --version
Step 4: Install pip (if not installed)
To install pip
, run:
sudo apt install python3-pip
3. Installing Python on macOS
Step 1: Install Homebrew (Optional but Recommended)
Homebrew is a package manager for macOS. It simplifies installing software, including Python. To install Homebrew:
1. Open the Terminal.
2. Run the following command
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: Install Python using Homebrew
If you have Homebrew installed, open the Terminal and run:
brew install python
This will install the latest version of Python along with pip
.
Step 3: Verify the Installation
After installation, verify it by running:
python3 --version
4. Setting up your development environment
Once Python is installed, you can set up your development environment. Here are a few popular tools:
Text Editors and IDEs:
VS Code: A lightweight, highly customizable code editor with Python support.
PyCharm: A full-fledged Python IDE with features like debugging, testing, and version control.
Sublime Text: A minimalistic text editor with Python plugins.
Setting Up a Virtual Environment:
It’s best practice to work within isolated environments for different projects. To create a virtual environment:
1. Install the venv
module if not already available
python3 -m pip install --user virtualenv
2. Create a virtual environment
python3 -m venv project_name
3. Activate the virtual environment
On Windows
project_name\Scripts\activate
On macOS/Linux
source project_name/bin/activate
Installing Packages:
Once the environment is active, you can install Python packages using pip
. For example:
pip install numpy
5. Running Python Programs
After setting up Python, you can run Python programs directly from the command line or your text editor.
Example:
Save the following code in a file named hello.py
:
print("Hello, World!")
To run the program, navigate to the folder where the file is located and use the following command:
python hello.py