In this tutorial, you will learn how to install Python on Windows, Linux, and macOS. I will explain step by step.
1. Installing Python on Windows
Step 1: Download Python
1. Firstly, visit the official Python website: python.org/downloads.
2. From the website, you have to 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. After installing Python, you have to 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
Python Installation – Questions and Answers
Q 1: From where can Python be downloaded?
Ans: Python can be downloaded from the official Python website.
Q 2: Why is Python installation required?
Ans: Python installation is required to write and execute Python programs on a system.
Q 3: How can you verify Python installation?
Ans: By running python --version in the command prompt or terminal.
Q 4: What is PIP in Python?
Ans: PIP is a tool used to install and manage Python libraries.
Q 5: What does adding Python to PATH do?
Ans: It allows Python commands to run from any directory.
Python Installation – Objective Questions (MCQs)
Q1. From where can Python be officially downloaded?
Q2. Which command is used to check Python version?
Q3. Which option should be checked while installing Python on Windows?
Q4. Which tool is used to install Python packages?
Q5. Which command installs a package using pip?