Installation and Setup
Install Python, set up your development environment, and write your first program using VS Code
Installation and Setup
Before writing Python code, you need to install Python and choose a code editor. This lesson walks through each step.
Installing Python
Windows
- Go to python.org/downloads
- Download Python 3.x for Windows
- Check "Add Python to PATH" during installation
- Click Install
Verify the installation:
python --versionmacOS
# Using Homebrew
brew install python3
# Verify
python3 --versionLinux
# Ubuntu/Debian
sudo apt update && sudo apt install python3 python3-pip
# Verify
python3 --versionOn macOS and Linux, type python3 instead of python. On Windows, just python works.
Choosing a Code Editor
VS Code (Recommended)
- Download from code.visualstudio.com
- Install the Python extension by Microsoft
- Install the Pylance language server
PyCharm
An IDE built specifically for Python, available in free (Community) and paid (Professional) editions.
Your First Python File
Create a file called hello.py:
# This is a comment
print("Hello, World!")
name = input("What is your name? ")
print(f"Nice to meet you, {name}!")Run it:
python hello.pyUsing the Python REPL
The REPL (Read-Eval-Print Loop) lets you test code interactively:
python>>> 5 * 7
35
>>> for i in range(3):
... print(i)
...
0
1
2
>>> exit()Working with pip
pip is Python's package manager:
# Install a package
pip install requests
# List installed packages
pip list
# Install from a requirements file
pip install -r requirements.txtVirtual Environments (Basic)
Isolate project dependencies:
# Create a virtual environment
python -m venv myenv
# Activate it (Windows)
myenv\Scripts\activate
# Activate it (macOS/Linux)
source myenv/bin/activateAlways use virtual environments for projects to avoid dependency conflicts!
Project Structure Conventions
my-project/
├── main.py
├── requirements.txt
├── README.md
└── myenv/ # Virtual environment (don't commit)
A good editor with the Python extension gives you: syntax highlighting, auto-completion, error checking, and debugging — all essential for productive coding.
Practice Questions
- What command checks your Python installation?
- What is the Python REPL used for?
- What does
pip install requestsdo? - Why should you use virtual environments?
- How do you activate a virtual environment on Linux?
- What extension should you install in VS Code for Python?
- What's the difference between an IDE and a text editor?
- How do you exit the Python REPL?
- What does
pip listshow? - Create a command that installs all packages from a requirements file.