Skip to main content
Python for Beginners
CHAPTER 02 Beginner

Installing Python and Setting Up Environment

Updated: May 17, 2026
15 min read

# Installing Python and Setting Up Environment

Welcome to Chapter 2! Now that you know what Python is and why it's amazing, it's time to install it on your computer and set up a professional development environment. By the end of this chapter, you'll have Python running and will have executed your first script.

---

1. Introduction

Before you can write Python code, you need two things:

  1. 1. Python itself — the interpreter that runs your code.
  1. 2. A code editor or IDE — a tool where you write your code comfortably.

Think of it like cooking: Python is the stove, and the IDE is your fully equipped kitchen with cutting boards, knives, and utensils. You *could* cook with just a stove, but a full kitchen makes everything easier and more efficient.

---

2. Learning Objectives

By the end of this chapter, you will be able to:

  • Download and install Python on Windows, macOS, and Linux.
  • Verify the Python installation via the command line.
  • Understand what pip is and how to use it.
  • Set up VS Code as your primary Python IDE.
  • Understand PyCharm basics.
  • Write and run your first Python script.
  • Use the Python interactive shell (REPL).

---

3. Installing Python on Windows

Step 1: Download Python

  1. 1. Go to https://www.python.org/downloads/
  1. 2. Click the big yellow "Download Python 3.x.x" button.

Step 2: Run the Installer

  1. 1. Double-click the downloaded .exe file.
  1. 2. ⚠️ CRITICAL: Check the box that says "Add Python to PATH" at the bottom of the installer. This is the most common mistake beginners make!
  1. 3. Click "Install Now".
123456789
Windows Installer Screen:
┌──────────────────────────────────────────┐
│  Install Python 3.12.x                   │
│                                          │
│  [x] Install launcher for all users      │
│  [✅] Add Python 3.12 to PATH  ← CHECK! │
│                                          │
│  [ Install Now ]  [ Customize ]          │
└──────────────────────────────────────────┘

Step 3: Verify Installation

Open Command Prompt (search "cmd" in Start menu) and type:
bash
1
python --version

Expected Output:

1
Python 3.12.x

Also verify pip (Python's package manager):

bash
1
pip --version

Expected Output:

1
pip 24.x.x from ... (python 3.12)

---

4. Installing Python on macOS

Option 1: Using the Official Installer

  1. 1. Visit python.org/downloads.
  1. 2. Download the macOS installer (.pkg file).
  1. 3. Run the installer and follow the prompts.
bash
12345
# Install Homebrew if not installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Python
brew install python

Verify Installation

bash
12
python3 --version
pip3 --version

> Note: On macOS, you may need to use python3 and pip3 instead of python and pip.

---

5. Installing Python on Linux

Most Linux distributions come with Python pre-installed. To check:

bash
1
python3 --version

If not installed, use your package manager:

Ubuntu / Debian

bash
12
sudo apt update
sudo apt install python3 python3-pip

Fedora

bash
1
sudo dnf install python3 python3-pip

Arch Linux

bash
1
sudo pacman -S python python-pip

---

6. Understanding pip

pip stands for "Pip Installs Packages" and is Python's official package manager. It lets you install third-party libraries from the Python Package Index (PyPI).

bash
1234567891011121314
# Install a package
pip install requests

# Install a specific version
pip install requests==2.31.0

# Upgrade a package
pip install --upgrade requests

# List installed packages
pip list

# Uninstall a package
pip uninstall requests

Common Useful Packages

PackagePurpose
requestsHTTP requests
flaskWeb development
pandasData analysis
numpyNumerical computing
matplotlibData visualization
beautifulsoup4Web scraping

---

7. Python IDEs and Code Editors

Visual Studio Code is a free, lightweight, and powerful code editor by Microsoft. It's the most popular editor for Python development.

Installation:

  1. 1. Download from code.visualstudio.com
  1. 2. Install and open VS Code.
  1. 3. Go to Extensions (Ctrl+Shift+X).
  1. 4. Search for "Python" by Microsoft and click Install.

1234567891011121314
VS Code Python Extension:
┌────────────────────────────────────────┐
│  🐍 Python (Microsoft)                │
│  ★★★★★  (45M+ downloads)              │
│                                        │
│  Features:                             │
│  • IntelliSense (auto-completion)      │
│  • Debugging                           │
│  • Linting (error detection)           │
│  • Jupyter Notebook support            │
│  • Virtual environment support         │
│                                        │
│  [ Install ]                           │
└────────────────────────────────────────┘

Recommended VS Code Extensions for Python:

  • Python (by Microsoft) — Core Python support
  • Pylance — Fast, feature-rich language server
  • Python Debugger — Debugging support
  • Code Runner — Run code with one click

7.2 PyCharm

PyCharm by JetBrains is a full-featured Python IDE.

  • Community Edition — Free, open-source (great for learning).
  • Professional Edition — Paid, with web development and database tools.

Installation:

  1. 1. Download from jetbrains.com/pycharm.
  1. 2. Install the Community Edition.
  1. 3. Create a new project and start coding.

7.3 Other Options

EditorBest For
IDLEAbsolute beginners (comes with Python)
Jupyter NotebookData science, exploration
Sublime TextLightweight editing
AtomOpen-source enthusiasts
ThonnyBeginner-focused IDE

---

8. The Python Interactive Shell (REPL)

Python comes with an interactive shell called the REPL (Read-Eval-Print Loop). It lets you execute Python code line by line — perfect for quick experiments.

How to Open:

Open your terminal and type python (or python3 on macOS/Linux):
bash
1
python

You'll see something like:

123
Python 3.12.x (main, ...)
Type "help", "copyright", "credits" or "license" for more information.
>>>

Try It:

```python id="py2_repl1" >>> print("Hello from the Python shell!") Hello from the Python shell!

>>> 2 + 2 4

>>> name = "Alice" >>> print(f"Welcome, {name}!") Welcome, Alice!

>>> exit() # To leave the shell

123456789
---

## 9. Writing and Running Your First Python Script

### Step 1: Create a File
Open VS Code and create a new file called `hello.py`.

### Step 2: Write the Code

python id="py2_ex1" # hello.py — Your very first Python script! print("Hello, World!") print("I am learning Python!") print("This is my first script! 🎉")

1234
### Step 3: Run the Script

**Option 1: Using the Terminal**

bash python hello.py

12345
**Option 2: Using VS Code**
- Click the **▶ Play button** in the top-right corner of VS Code.
- Or press **Ctrl+F5** (Run Without Debugging).

**Output:**

Hello, World! I am learning Python! This is my first script! 🎉

1234
---

## 10. Understanding Python File Structure

Your Python file (.py): ┌──────────────────────────────────┐ │ # Comments (notes for humans) │ │ # They start with # │ │ │ │ import math ← Module imports │ │ │ │ name = "Alice" ← Variables │ │ age = 25 │ │ │ │ def greet(): ← Functions │ │ print(f"Hi, {name}!") │ │ │ │ greet() ← Function call │ └──────────────────────────────────┘

123456
---

## 11. Code Examples

### Example 1: Using Multiple Print Statements

python id="py2_ex2" print("=" * 40) print(" Python Installation Successful!") print("=" * 40)

1
**Output:**

======================================== Python Installation Successful! ========================================

12
### Example 2: Quick Math in Python

python id="py2ex3" # mathtest.py import math

radius = 5 area = math.pi * radius ** 2 print(f"Area of circle with radius {radius}: {area:.2f}")

1
**Output:**

Area of circle with radius 5: 78.54

12
### Example 3: Checking Your Python Environment

python id="py2ex4" # environmentinfo.py import sys import platform

print(f"Python Version : {sys.version}") print(f"Platform : {platform.system()} {platform.release()}") print(f"Architecture : {platform.architecture()[0]}") print(f"Processor : {platform.processor()}") ``

---

12. Common Mistakes

  1. 1. Not adding Python to PATH: If python --version doesn't work, you likely forgot to check "Add to PATH" during installation. Reinstall and check the box.
  1. 2. Using python vs python3: On macOS/Linux, python might point to Python 2. Always use python3.
  1. 3. Saving files without .py extension: Your files must end in .py for Python to recognize them.
  1. 4. Running code in the wrong directory: Make sure your terminal is in the same directory as your .py file.
  1. 5. Not installing the Python VS Code extension: Without it, you won't get syntax highlighting or auto-completion.

---

13. Best Practices

  • Always use the latest Python 3 version — Stay updated for security and features.
  • Use virtual environments — Isolate project dependencies (covered in Chapter 15).
  • Organize your files — Create separate folders for each project.
  • Use VS Code with the Python extension — It provides the best balance of simplicity and power.
  • Practice in the REPL — Use the interactive shell for quick experiments.

---

14. Exercises

  1. 1. Install Python on your computer and verify the version using the command line.
  1. 2. Install VS Code and the Python extension.
  1. 3. Create a file called myinfo.py that prints your name, age, and favorite hobby.
  1. 4. Open the Python REPL and perform 5 different math operations.
  1. 5. Use pip list to see all installed packages on your system.

---

15. MCQs with Answers

Q1: What is the official website to download Python? A) python.com B) python.org C) python.dev D) getpython.org Answer: B — The official Python website is python.org.

Q2: What must you check during Windows installation? A) Install for all users B) Add Python to PATH C) Use custom installation D) Install documentation Answer: B — Adding Python to PATH is critical for command-line access.

Q3: What is pip? A) Python Integrated Platform B) Python Installation Program C) Pip Installs Packages D) Python Interface Protocol Answer: C — pip stands for "Pip Installs Packages."

Q4: What command checks your Python version? A) python -v B) python --version C) python -check D) python version Answer: B — python --version displays the installed version.

Q5: Which VS Code extension is essential for Python? A) Python by Microsoft B) Java Extension Pack C) Live Server D) ESLint Answer: A — The Python extension by Microsoft provides IntelliSense, debugging, and more.

Q6: What is REPL? A) Run-Execute-Process-Loop B) Read-Eval-Print-Loop C) Read-Execute-Parse-Load D) Run-Evaluate-Program-Log Answer: B — REPL stands for Read-Eval-Print-Loop.

Q7: What file extension do Python files use? A) .python B) .pt C) .py D) .pn Answer: C — Python files use the .py extension.

Q8: Which command installs a package using pip? A) pip get requests B) pip download requests C) pip install requests D) pip add requests Answer: C — pip install packagename is the correct command.

Q9: What is PyCharm? A) A Python library B) A Python IDE by JetBrains C) A Python testing framework D) A Python web framework Answer: B — PyCharm is a full-featured IDE by JetBrains.

Q10: How do you exit the Python REPL? A) quit B) stop() C) exit() D) close() Answer: C — Type exit() or quit() to leave the REPL.

---

16. Interview Questions

  1. 1. How do you install Python on different operating systems?
*Answer:* On Windows, download from python.org and run the installer (checking "Add to PATH"). On macOS, use Homebrew (
brew install python) or the official installer. On Linux, use the package manager (e.g., sudo apt install python3).
  1. 2. What is pip and how do you use it?
*Answer:* pip is Python's package manager that installs third-party libraries from PyPI. Usage:
pip install packagename, pip uninstall packagename, pip list.
  1. 3. What is a virtual environment and why is it important?
*Answer:* A virtual environment is an isolated Python environment for a project. It prevents package conflicts between different projects by keeping dependencies separate.
  1. 4. What is the difference between an IDE and a text editor?
*Answer:* An IDE (like PyCharm) includes built-in tools for debugging, testing, version control, and project management. A text editor (like VS Code with extensions) is lighter but can be extended with plugins to achieve similar functionality.
  1. 5. How do you run a Python script from the command line?
*Answer:* Navigate to the directory containing the script and run
python script_name.py (or python3 on macOS/Linux).

---

17. FAQs

Q: Do I need to uninstall Python 2 before installing Python 3? A: No. They can coexist. However, make sure your PATH points to Python 3.

Q: Can I have multiple versions of Python installed? A: Yes. Use tools like pyenv to manage multiple Python versions easily.

Q: Is IDLE a good editor for beginners? A: IDLE is fine for absolute beginners, but VS Code is a much better investment of your time as it scales with your skills.

Q: Do I need internet to run Python? A: No. Once installed, Python runs completely offline. You only need internet to install packages via pip.

Q: What is the difference between python and python3 commands? A: On some systems, python refers to Python 2. The python3 command explicitly calls Python 3. On modern Windows installations, python usually points to Python 3.

---

18. Summary

  • Download Python from python.org and always check "Add to PATH".
  • Use pip to install third-party packages.
  • VS Code with the Python extension is the recommended editor for beginners.
  • The Python REPL (interactive shell) is great for quick experiments.
  • Python files use the .py extension and are run with python filename.py.
  • Always use Python 3 — Python 2 is no longer maintained.

---

19. Next Chapter Recommendation

You've successfully installed Python and set up your development environment. Now it's time to write real code! In Chapter 3: Python Syntax and First Program, we'll learn Python's syntax rules, understand indentation, explore comments, master the print()` function, and build a simple calculator. Let's code! 🚀

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·