← Back to Chapters

Python Installation

? Python Installation

⚡ Quick Overview

In this section, you will install Python on Windows, macOS, or Linux, verify that the installation works, ensure pip is available, and run a small test program. All steps are based on the official Python installer and your system’s package manager.

? Key Concepts

  • Download Python from the official Python Downloads page.
  • On Windows, always select Add Python to PATH before installing.
  • On macOS and Linux, you often use python3 instead of python.
  • pip is the package manager used to install extra Python libraries.
  • Virtual environments (venv) help you isolate project dependencies.

? Installation Steps

⬇️ Downloading Python

Go to the official Python Downloads page and download the installer for your operating system.

? Installing on Windows

  • Run the downloaded executable.
  • Check "Add Python to PATH".
  • Click "Install Now".

? Installing on macOS

  • Open the downloaded .pkg file.
  • Follow the installation instructions.
  • Verify installation using the terminal command below.
? Check Python version (macOS)
python3 --version

? Installing on Linux

Use your distribution's package manager to install Python 3.

? Ubuntu / Debian

? Install Python on Ubuntu / Debian
sudo apt-get install python3

? Fedora

? Install Python on Fedora
sudo dnf install python3

? Commands and Code Examples

? Verifying Installation

Open a terminal or command prompt and run:

? Check installed Python version
python --version
# or
python3 --version

? Checking pip

Pip comes pre-installed with Python 3.4+. You can check it with:

? Check pip version
pip --version
# or
pip3 --version

✨ First Python Program

Open your terminal or IDE and run this simple program:

? Print a welcome message
print("Hello, Python!")

? Creating a Virtual Environment

Use virtual environments to isolate dependencies for each project:

? Create a virtual environment
python -m venv myenv

? Live Output / Explanation

? What You Should See

  • Running python --version or python3 --version should display something like Python 3.x.x.
  • pip --version should show the pip version and the Python path it is linked to.
  • Running print("Hello, Python!") will output: Hello, Python! in your terminal or IDE console.
  • After python -m venv myenv, a new folder named myenv will appear, containing the isolated environment files.

If the version commands fail or are not recognized, the most common issue is that Python was not added to your system PATH, or your system expects python3 instead of python.

✅ Tips

  • You can manage multiple Python versions using tools like pyenv.
  • Always check "Add Python to PATH" during Windows installation.
  • Prefer using python3 and pip3 on macOS and Linux if both Python 2 and 3 exist.
  • Create a separate virtual environment for each project to avoid dependency conflicts.

? Try It Yourself

  • Create a file named hello.py and print "Hello, Python!".
  • Set up a virtual environment using python -m venv testenv and activate it.
  • Verify pip installation and install a package like requests using pip install requests.