Environment Setup
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:
- The Python Interpreter: The engine that reads your
.pytext files, interprets the code line by line, and translates it into instructions your computer’s CPU can execute. - 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
- Head to the official website at python.org/downloads.
- Click the yellow button to download the latest Python release for Windows.
- Launch the downloaded
.exeinstaller. - CRITICAL STEP: At the bottom of the first setup window, check the box that says:
[x] Add python.exe to PATHIf you forget to check this box, your terminal will not recognize the
pythoncommand later. - Click Install Now.
- 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:
- Visit python.org/downloads and download the macOS
.pkginstaller. - Run the installer and follow the on-screen prompts.
- 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
cmdorPowerShell, and hit Enter. - macOS: Press
Cmd + Space, typeTerminal, 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 + Zthen Enter on Windows, orCtrl + Don 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
- Download VS Code for free from code.visualstudio.com.
- Install and launch it.
Installing the Python Extension
- Inside VS Code, click the Extensions icon on the left sidebar (it looks like four building blocks).
- In the search bar, type
Python. - Locate the official extension by Microsoft and click Install.
- 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
- On your computer (e.g., your Desktop or Documents), create a new folder named
python_projects. - In VS Code, go to File > Open Folder… and select your
python_projectsfolder.
2. Create a Script File
-
In the VS Code file explorer on the left, click the New File icon.
-
Name the file
hello.py.Always save Python files with the
.pyextension. This tells your editor and operating system that the file contains Python code. -
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}!")
- Save the file (
Ctrl + Son Windows,Cmd + Son 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 the1` key) or go to the top menu and select Terminal > New Terminal. - Notice that the terminal opens automatically inside your
python_projectsfolder.
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 |
|---|---|---|
pwd | cd | Print Working Directory (shows which folder you are currently inside) |
ls | dir | List files and folders in your current directory |
cd my_folder | cd my_folder | Move into my_folder |
cd .. | cd .. | Move up one folder level |
clear | cls | Clear 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.