Module 1 ยท Lesson 2

Installing Python and Setting Up Your Environment

๐Ÿ Pythonโฑ 12 min read๐Ÿ“– Setup

Installation by Operating System

Getting Python running is the first real step. The process varies by OS, but the goal is the same: a working python3 command in your terminal.

Windows

  1. Go to python.org/downloads and download the latest Python 3.x installer.
  2. Run the installer. Critical: check "Add Python to PATH" before clicking Install Now. Without this, you'll get "python is not recognized" errors forever.
  3. Open Command Prompt or PowerShell and verify:
python --version # Python 3.12.x pip --version # pip 24.x
Windows Gotcha

On Windows, the command might be python instead of python3. If python3 fails, try python. If neither works, Python isn't in your PATH โ€” reinstall and check that box.

macOS

macOS ships with Python 2 for legacy scripts. You need Python 3:

# Option 1: Official installer from python.org (easiest for beginners) # Download .pkg from https://python.org/downloads/mac-osx/ # Option 2: Homebrew (recommended for developers) brew install python3 # Verify python3 --version pip3 --version

Linux

# Check if Python 3 is already installed python3 --version # Ubuntu/Debian โ€” install if needed sudo apt update && sudo apt install python3 python3-pip # Fedora/RHEL sudo dnf install python3 python3-pip # Arch sudo pacman -S python python-pip

Choosing an Editor

You can write Python in any text editor, but a proper IDE makes development far faster. Here are your options:

EditorBest ForFree?
VS CodeAll-around development, most popular by farโœ“ Free
PyCharmProfessional Python, large projects, DjangoCommunity edition free
Jupyter NotebookData science, interactive explorationโœ“ Free
Vim/NeovimTerminal power usersโœ“ Free
IDLEBeginners, comes bundled with Pythonโœ“ Free

Recommendation for beginners: VS Code with the Python extension. It gives you syntax highlighting, autocomplete (IntelliSense), debugging, and an integrated terminal โ€” all for free.

Setting Up VS Code for Python

  1. Download VS Code from code.visualstudio.com
  2. Install the Python extension (publisher: ms-python)
  3. Install Pylance for better type-aware intellisense
  4. Open a .py file โ€” VS Code will detect your Python interpreter automatically
  5. Select your interpreter: Ctrl+Shift+P โ†’ "Python: Select Interpreter"

Virtual Environments

Every Python project should have its own isolated environment. This prevents package version conflicts between projects. It's professional practice โ€” start doing this from day one.

# Create a virtual environment in the current directory python3 -m venv venv # Activate it source venv/bin/activate # macOS/Linux .\venv\Scripts\activate # Windows PowerShell # Your terminal prompt changes to show (venv) # Now install packages โ€” they're isolated to this project pip install requests # Deactivate when done deactivate # Save your dependencies pip freeze > requirements.txt # Reproduce environment elsewhere pip install -r requirements.txt
Always Activate First

Before working on any Python project, activate its virtual environment. Check your prompt โ€” if you see (venv), you're good. If not, you might be installing packages globally.

Verifying Everything Works

# Check Python version (should be 3.8+) python3 --version # Check pip pip3 --version # Launch the interactive REPL python3 # >>> appears โ€” you're in Python! >>> 2 + 2 4 >>> print("Hello from Python!") Hello from Python! >>> exit() # or Ctrl+D to quit

Key Takeaways

Practice Exercises

  1. Install Python and confirm python3 --version works in your terminal.
  2. Open the Python REPL and type 2 ** 10. What's the result?
  3. Install VS Code with the Python extension. Create a file hello.py that prints your name.
  4. Create a virtual environment called learning, activate it, install the requests package, then deactivate.
โ† What is Python