Browse Python Topics ▼
Pick a Web Framework

Environment Setup

📂 Getting Started 📘 Lesson 2 of 57

Install Python, navigate the command line, configure VS Code, and run your very first script without getting stuck on path errors.

In intro-to-programming, you learned that computers need precise instructions. To start giving those instructions, you need two fundamental tools installed on your computer:

  1. The Python Interpreter: The engine that reads your .py text files, interprets the code line by line, and translates it into instructions your computer’s CPU can execute.
  2. A Code Editor: A specialized workspace (like Visual Studio Code) designed for writing code with syntax coloring, error highlighting, and an integrated terminal.

Think of it like cooking: the code editor is your kitchen counter and cutting board (where you prepare the recipe), while the Python interpreter is the stove (where the actual work happens).


Step 1: Installing Python

Python is free, open source, and available on every major operating system.

On Windows

  1. Head to the official website at python.org/downloads.
  2. Click the yellow button to download the latest Python release for Windows.
  3. Launch the downloaded .exe installer.
  4. CRITICAL STEP: At the bottom of the first setup window, check the box that says: [x] Add python.exe to PATH

    If you forget to check this box, your terminal will not recognize the python command later.

  5. Click Install Now.
  6. When the installation finishes, click Disable path length limit if prompted, then click Close.

On macOS

macOS comes with an older system Python used internally by Apple, but you should install the latest modern version:

  1. Visit python.org/downloads and download the macOS .pkg installer.
  2. Run the installer and follow the on-screen prompts.
  3. Alternatively, if you use the Homebrew package manager, open your terminal and run:
    brew install python

On Linux (Ubuntu / Debian / Raspberry Pi)

Most Linux distributions come with Python 3 pre-installed. Open your terminal and install Python along with pip (Python’s package manager):

sudo apt update
sudo apt install python3 python3-pip

Step 2: Verifying Your Installation

Once installed, verify that your computer recognizes Python through your operating system’s terminal.

Opening Your Terminal

  • Windows: Press the Windows key, type cmd or PowerShell, and hit Enter.
  • macOS: Press Cmd + Space, type Terminal, and hit Enter.
  • Linux: Press Ctrl + Alt + T.

Now, type the following command and press Enter:

python --version

(On macOS or Linux, you may need to type python3 --version)

If Python is installed correctly, you will see output like:

Python 3.12.2

Troubleshooting: “Command Not Found” or “‘python’ is not recognized” If you are on Windows and see an error saying the command was not recognized, the installer did not add Python to your PATH variable. Run the Python installer again, choose Modify, check Add python.exe to PATH, and restart your terminal.


Step 3: Meeting the Python REPL

Python comes with an interactive shell called the REPL, which stands for Read-Eval-Print Loop:

  • Read: It reads the command you type.
  • Eval: It evaluates (runs) the code.
  • Print: It prints the result to the screen.
  • Loop: It waits for your next command.

To enter the REPL, type python (or python3 on Mac/Linux) into your terminal and press Enter:

python

You will see three arrows (>>>), which is Python’s prompt waiting for your input:

Python 3.12.2 (main, Feb 20 2024) [Clang 15.0.0] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Try typing arithmetic or a print statement right here:

>>> 25 * 4
100
>>> print("Hello from the REPL!")
Hello from the REPL!

The REPL is fantastic for testing small snippets of code and quick calculations.

To exit the REPL and return to your regular terminal prompt:

  • Type exit() and press Enter, or
  • Press Ctrl + Z then Enter on Windows, or Ctrl + D on macOS/Linux.

Step 4: Setting Up Visual Studio Code

While the REPL is great for quick tests, real software is saved in files so you can run, share, and expand your code later.

You should never write code in a word processor like Microsoft Word or Apple Pages—they insert invisible formatting marks that confuse programming interpreters. Instead, use a dedicated code editor. The industry standard across software engineering is Visual Studio Code (VS Code).

Installing VS Code

  1. Download VS Code for free from code.visualstudio.com.
  2. Install and launch it.

Installing the Python Extension

  1. Inside VS Code, click the Extensions icon on the left sidebar (it looks like four building blocks).
  2. In the search bar, type Python.
  3. Locate the official extension by Microsoft and click Install.
  4. This extension gives you intelligent auto-completion (IntelliSense), syntax color coding, and quick debugging tools.

Step 5: Writing and Running Your First Script File

Let’s create a dedicated folder for your Python projects and write your first saved script.

1. Create a Project Folder

  1. On your computer (e.g., your Desktop or Documents), create a new folder named python_projects.
  2. In VS Code, go to File > Open Folder… and select your python_projects folder.

2. Create a Script File

  1. In the VS Code file explorer on the left, click the New File icon.

  2. Name the file hello.py.

    Always save Python files with the .py extension. This tells your editor and operating system that the file contains Python code.

  3. Type the following code into hello.py:

# Our first Python script
user_name = "Future Engineer"
print("Setting up your Python environment was a success!")
print(f"Welcome aboard, {user_name}!")
  1. Save the file (Ctrl + S on Windows, Cmd + S on Mac).

3. Open the Integrated Terminal in VS Code

You do not need to switch back and forth between VS Code and an external terminal window. VS Code has a terminal built right in:

  • Press Ctrl + \`` (the backtick key, next to the 1` key) or go to the top menu and select Terminal > New Terminal.
  • Notice that the terminal opens automatically inside your python_projects folder.

4. Run the Script

In the integrated terminal, type:

python hello.py

(Use python3 hello.py on macOS or Linux if needed)

Press Enter, and you will see your script’s output:

Setting up your Python environment was a success!
Welcome aboard, Future Engineer!

Congratulations—you have officially configured a professional Python development environment on your computer!


Essential Terminal Commands Cheat Sheet

As a programmer, the command line is your direct control panel. Here are the five terminal navigation commands you will use every day:

Command (Mac/Linux)Command (Windows)What It Does
pwdcdPrint Working Directory (shows which folder you are currently inside)
lsdirList files and folders in your current directory
cd my_foldercd my_folderMove into my_folder
cd ..cd ..Move up one folder level
clearclsClear the terminal screen

Pro-Tip: When typing folder or file names in the terminal, type the first 2 or 3 letters and press the Tab key. The terminal will auto-complete the rest of the name for you!


What’s Next?

With your environment configured and verified, you are ready to explore how Python transforms your text into machine execution behind the scenes.

Continue to how-python-works to understand interpreters, compilers, and bytecode, or dive straight into writing code with syntax-and-comments. When building larger applications later, you will isolate project dependencies using virtual-environments. To master the command line environment, explore linux-terminal-basics, and to track code history, learn git-basics.

Test your understanding of Environment Setup

Quick interactive practice questions with instant feedback.

Take Quiz →