KAHIBARO Bookshelves
Discord Login Register

2.1. Installing Python (Windows / macOS / Linux)

Before You Install

To write and run Python programs on your computer, you first need the Python interpreter installed. The steps are slightly different depending on whether you use Windows, macOS, or Linux.

This chapter focuses only on:

  • How to check if Python is already installed
  • How to install Python on each operating system
  • A few important options to select during installation
  • How to confirm that the installation worked

We’ll use the official CPython distribution from https://www.python.org.


Step 1: Check if Python Is Already Installed

You might already have Python on your system. Let’s quickly check.

On Windows

  1. Open Command Prompt:
    • Press Win key, type cmd, press Enter.
  2. In the black window, type:
text
   python --version

and press Enter.

  1. Possible results:
    • If you see something like:
text
     Python 3.12.1

then Python 3 is installed.

  • If you see an error like:
text
     'python' is not recognized as an internal or external command...

then Python is not installed or not on your PATH.

Also try:

text
py --version

Some Windows installations use py as the Python launcher.

On macOS

  1. Open Terminal:
    • Press Cmd + Space, type Terminal, press Enter.
  2. Type:
bash
   python3 --version

and press Enter.

  1. If you see:
text
   Python 3.x.x

then Python 3 is installed.

If it says command not found or only shows Python 2 (e.g. Python 2.7.x for python), you still need to install a recent Python 3.

On Linux

  1. Open your terminal.
  2. Type:
bash
   python3 --version

and press Enter.

  • If you see Python 3.x.x, you already have Python 3.
  • If not, you’ll install it using your distribution’s package manager or from python.org.

Step 2: Downloading Python (All Systems)

  1. Go to the official site:
    • Open a browser and visit:
      https://www.python.org/downloads/
  2. The site usually detects your operating system and shows a big button such as:
    • “Download Python 3.x.x”
  3. Make sure the version number starts with 3 (e.g. 3.12.1), not 2.

You’ll now follow the steps specific to your operating system.


Installing Python on Windows

1. Run the Installer

  1. Download the Windows installer (usually a .exe file).
  2. Double-click the downloaded file to start the installer.

You’ll see a window titled something like “Install Python 3.x.x”.

2. Important Options on the First Screen

Look carefully at the first installer screen:

  • At the bottom, you should see a checkbox:
    • Add python.exe to PATH

Check this box.
This makes it possible to run Python from the Command Prompt without extra setup.

Next, for beginners, click:

  • Install Now (recommended)

You do not need “Customize installation” for basic use.

3. Allow Changes and Wait

  • If Windows asks whether to allow the app to make changes, click Yes.
  • The installer will copy files and set up Python. This may take a minute.

When it finishes, you should see a “Setup was successful” message.

4. Verify the Installation

  1. Open Command Prompt again.
  2. Type:
text
   python --version

or

text
   py --version
  1. You should now see something like:
text
   Python 3.12.1

If this works, Python is correctly installed and available from the command line.

5. Optional: Check IDLE and Start Menu Entries

After installation, you should find:

  • In the Start menu, search for IDLE (Python’s simple built-in editor).
  • Also search for Python to see menu entries like:
    • “Python 3.x”
    • “IDLE (Python 3.x 64-bit)”
    • “Python Manuals”

These confirm that the installer set up shortcuts correctly.


Installing Python on macOS

You have two common options:

  • Use the official Python installer from python.org (recommended for beginners).
  • Use a package manager like Homebrew (more common for advanced users).

We’ll focus on the official installer.

1. Run the Official Installer

  1. From https://www.python.org/downloads/, download the macOS installer (.pkg file).
  2. Open the downloaded .pkg file.
  3. A standard macOS installer window opens.

2. Go Through the Installer Steps

  • Click Continue through the introduction and license screens.
  • Accept the license if you agree.
  • Click Install to install for all users (or just your account, depending on options).
  • Enter your macOS password if prompted.

Wait for the installation to complete. You should see a “The installation was successful” message.

3. Verify the Installation in Terminal

  1. Open Terminal (Cmd + Space, type Terminal).
  2. Type:
bash
   python3 --version
  1. You should see:
text
   Python 3.x.x

If that works, Python 3 is installed.

On macOS, you’ll usually use python3 and pip3 instead of python and pip.

4. Check the Installed Applications

The official installer usually adds:

  • A folder under Applications called Python 3.x
    • This may include:
      • IDLE
      • Python Launcher
      • Documentation

You can open IDLE from there if you want a simple place to type Python code.


Installing Python on Linux

Many Linux distributions already include Python 3, but sometimes it’s an older version. The way you install or update Python depends on your distribution.

Below are common instructions for major families. Always use python3 (not python) when in doubt.

1. Check Existing Python 3

In your terminal:

bash
python3 --version
  • If this shows Python 3.x.x, you may already be fine for beginner work.
  • If it’s missing or very old, install/update using your package manager.

2. Debian / Ubuntu / Linux Mint (APT)

Use the apt package manager.

First, update package information:

bash
sudo apt update

Then install Python 3 (and often pip):

bash
sudo apt install python3 python3-pip

Verify:

bash
python3 --version

3. Fedora (DNF)

Use the dnf package manager:

bash
sudo dnf install python3

Verify:

bash
python3 --version

4. openSUSE (Zypper)

Use zypper:

bash
sudo zypper install python3

Verify:

bash
python3 --version

5. Arch / Manjaro (pacman)

Arch-based systems often have up-to-date Python in the repos:

bash
sudo pacman -S python

Verify:

bash
python --version

On some Arch systems, python already points to Python 3.

6. Using the Official Python Installer on Linux

Advanced users may choose to compile Python from source downloaded from python.org, but for beginners, using your distribution’s package manager is usually easier and less error-prone.


Common Installation Issues and Quick Checks

“Command Not Found” or “Not Recognized”

If you see errors like:

  • Windows:
text
  'python' is not recognized as an internal or external command...
  • macOS/Linux:
text
  command not found: python3

Check:

  • Did you actually install Python 3?
  • On Windows, did you check “Add python.exe to PATH” during installation?
  • On macOS/Linux, are you using python3 instead of python?

On Windows, if you forgot the PATH option, you can:

  • Re-run the installer and choose “Modify”, then make sure the PATH option is selected, or
  • Reinstall and this time check “Add python.exe to PATH”.

Multiple Python Versions

You might have both Python 2 and Python 3 installed.

  • On Windows, python usually runs Python 3 (with recent installers).
  • On macOS and Linux, python may be Python 2, so use python3.

Always explicitly use:

bash
python3

in this course unless instructions say otherwise.


Final Verification Checklist

After following the steps for your operating system, you should be able to:

  1. Open a terminal or command prompt.
  2. Type one of these (depending on your OS):
    • Windows:
text
     python --version

or

text
     py --version
  • macOS/Linux:
bash
     python3 --version
  1. See a response like:
text
   Python 3.x.x

If you get that, Python is correctly installed and ready to use in the next chapters.

Views: 0

Comments

Please login to add a comment.

Don't have an account? Register now!

Where to Move

Move chapter:

  • ☰ 1. Chapter 1: What Is Programming?
    • ☰ 1.1. What is a computer program?
      • ☰ 1.2. What is Python?
        • ☰ 1.3. Where is Python used?
          • ☰ 1.4. How programming helps solve problems
            • ☰ 1.5. Your first Python program
            • ☰ 2. Chapter 2: Setting Up Python
              • ☰ 2.1. Installing Python (Windows / macOS / Linux)
                • ☰ 2.2. Using Python in the terminal
                  • ☰ 2.3. Using an IDE (IDLE / VS Code)
                    • ☰ 2.4. Running Python scripts
                      • ☰ 2.5. Python interactive mode
                      • ☰ 3. Chapter 3: Variables and Data Types
                        • ☰ 3.1. What is a variable?
                          • ☰ 3.2. Creating variables
                            • ☰ 3.3. Numbers
                              • ☰ 3.4. Test
                                • ☰ 3.5. Boolean values
                                  • ☰ 3.6. Type checking
                                  • ☰ 4. Chapter 4: Basic Operations
                                    • ☰ 4.1. Arithmetic operations
                                      • ☰ 4.2. Working with numbers
                                        • ☰ 4.3. String operations
                                          • ☰ 4.4. Combining text and variables
                                            • ☰ 4.5. Comments in Python
                                            • ☰ 5. Chapter 5: User Input and Output
                                              • ☰ 5.1. Getting input from the user
                                                • ☰ 5.2. Converting input to numbers
                                                  • ☰ 5.3. Formatting output
                                                    • ☰ 5.4. Writing interactive programs
                                                    • ☰ 6. Chapter 6: Conditions
                                                      • ☰ 6.1. Comparison operators
                                                        • ☰ 6.2. Logical operators
                                                          • ☰ 6.3. if, elif, else
                                                            • ☰ 6.4. Nested conditions
                                                              • ☰ 6.5. Common beginner mistakes
                                                              • ☰ 7. Chapter 7: Loops
                                                                • ☰ 7.1. Why loops are useful
                                                                  • ☰ 7.2. for loops
                                                                    • ☰ 7.3. while loops
                                                                      • ☰ 7.4. Loop counters
                                                                        • ☰ 7.5. break and continue
                                                                          • ☰ 7.6. Loop exercises
                                                                          • ☰ 8. Chapter 8: Data Collections
                                                                            • ☰ 8.1. Lists
                                                                              • ☰ 8.2. Tuples
                                                                                • ☰ 8.3. Dictionaries
                                                                                  • ☰ 8.4. Sets (basics)
                                                                                    • ☰ 8.5. Choosing the right data structure
                                                                                    • ☰ 9. Chapter 9: Functions
                                                                                      • ☰ 9.1. Why functions matter
                                                                                        • ☰ 9.2. Defining functions
                                                                                          • ☰ 9.3. Parameters and arguments
                                                                                            • ☰ 9.4. Return values
                                                                                              • ☰ 9.5. Scope (local vs global)
                                                                                                • ☰ 9.6. Reusing code
                                                                                                • ☰ 10. Chapter 10: Working with Files
                                                                                                  • ☰ 10.1. What is a file?
                                                                                                    • ☰ 10.2. Reading text files
                                                                                                      • ☰ 10.3. Writing and appending files
                                                                                                        • ☰ 10.4. File paths
                                                                                                          • ☰ 10.5. Simple file-based programs
                                                                                                          • ☰ 11. Chapter 11: Errors and Debugging
                                                                                                            • ☰ 11.1. Types of errors
                                                                                                              • ☰ 11.2. Reading error messages
                                                                                                                • ☰ 11.3. Common beginner errors
                                                                                                                  • ☰ 11.4. try and except
                                                                                                                    • ☰ 11.5. Debugging strategies
                                                                                                                    • ☰ 12. Chapter 12: Using Python Libraries
                                                                                                                      • ☰ 12.1. What is a library?
                                                                                                                        • ☰ 12.2. Importing modules
                                                                                                                          • ☰ 12.3. Standard libraries
                                                                                                                            • ☰ 12.3.1. math
                                                                                                                              • ☰ 12.3.2. random
                                                                                                                                • ☰ 12.3.3. datetime
                                                                                                                                • ☰ 12.4. Installing external libraries with pip
                                                                                                                                • ☰ 13. Chapter 13: Object-Oriented Programming
                                                                                                                                  • ☰ 13.1. What is object-oriented programming?
                                                                                                                                    • ☰ 13.2. Classes and objects
                                                                                                                                      • ☰ 13.3. The `__init__` method
                                                                                                                                        • ☰ 13.4. Attributes and methods
                                                                                                                                          • ☰ 13.5. Encapsulation
                                                                                                                                            • ☰ 13.6. Inheritance (basics)
                                                                                                                                              • ☰ 13.7. Simple OOP examples
                                                                                                                                              • ☰ 14. Chapter 14: Automation with Python
                                                                                                                                                • ☰ 14.1. What is automation?
                                                                                                                                                  • ☰ 14.2. Automating simple tasks
                                                                                                                                                    • ☰ 14.3. Working with files and folders
                                                                                                                                                      • ☰ 14.4. Automating text processing
                                                                                                                                                        • ☰ 14.5. Scheduling scripts
                                                                                                                                                          • ☰ 14.6. Practical automation examples
                                                                                                                                                          • ☰ 15. Chapter 15: Web Development with Python
                                                                                                                                                            • ☰ 15.1. How the web works (basic overview)
                                                                                                                                                              • ☰ 15.2. Introduction to Flask
                                                                                                                                                                • ☰ 15.3. Creating a simple web server
                                                                                                                                                                  • ☰ 15.4. Routing and templates
                                                                                                                                                                    • ☰ 15.5. Handling user input (forms)
                                                                                                                                                                      • ☰ 15.6. Very basic APIs
                                                                                                                                                                      • ☰ 16. Chapter 16: Data Science with Python
                                                                                                                                                                        • ☰ 16.1. What is data science?
                                                                                                                                                                          • ☰ 16.2. Working with data
                                                                                                                                                                            • ☰ 16.3. Introduction to NumPy
                                                                                                                                                                              • ☰ 16.4. Introduction to pandas
                                                                                                                                                                                • ☰ 16.5. Data visualization with matplotlib
                                                                                                                                                                                  • ☰ 16.6. Simple data analysis examples
                                                                                                                                                                                  • ☰ 17. Chapter 17: Mini Projects
                                                                                                                                                                                    • ☰ 17.1. Number guessing game
                                                                                                                                                                                      • ☰ 17.2. Simple calculator
                                                                                                                                                                                        • ☰ 17.3. To-do list
                                                                                                                                                                                          • ☰ 17.4. Password generator
                                                                                                                                                                                            • ☰ 17.5. Quiz application
                                                                                                                                                                                              • ☰ 17.6. Small web or data project
                                                                                                                                                                                              • ☰ 18. Chapter 18: Next Steps
                                                                                                                                                                                                • ☰ 18.1. How to practice Python
                                                                                                                                                                                                  • ☰ 18.2. Writing clean and readable code
                                                                                                                                                                                                    • ☰ 18.3. Choosing a specialization
                                                                                                                                                                                                      • ☰ 18.3.1. Web development
                                                                                                                                                                                                        • ☰ 18.3.2. Data science
                                                                                                                                                                                                          • ☰ 18.3.3. Automation
                                                                                                                                                                                                            • ☰ 18.3.4. Software development
                                                                                                                                                                                                            • ☰ 18.4. Learning resources and communities
                                                                                                                                                                                                            • ☰ 19. Appendix
                                                                                                                                                                                                              • ☰ 19.1. Python syntax cheat sheet
                                                                                                                                                                                                                • ☰ 19.2. Common errors and solutions
                                                                                                                                                                                                                  • ☰ 19.3. Glossary of terms