Set Up Your Python Environment (Python + VS Code/IDLE)
Overview
Follow step-by-step instructions to install Python on your computer and set up an integrated development environment (IDE) like VS Code or IDLE. You’ll also learn how to configure paths and check your installation using the terminal or command prompt.
What You Will Learn in This Lesson
By the end of this lesson, you will know:
- What Python needs to run on your computer: Understanding the difference between Python (the language) and an IDE (where you write code), and why you need both.
- How to install Python the correct and safe way: Step-by-step instructions for Windows and Mac, including important settings like adding Python to PATH.
- What an IDE is and why you need one: Learn what Integrated Development Environments do and how they make coding easier with features like syntax highlighting and error detection.
- How to write and run your first real
.pyfile: Create an actual Python file, write code in it, and execute it to see your program run.
Beginner-Friendly
This lesson is very beginner-friendly. No previous experience is needed. We'll explain every step in detail, including what each tool does and why you need it.
Step 1: What You Need to Install
To start coding in Python, you need two essential tools installed on your computer:
1. Python Itself
This is the actual programming language interpreter. Think of it as the engine that runs your Python code. When you install Python, you're installing a program that can read .py files and execute the instructions inside them. Without Python installed, your computer won't understand Python code at all.
2. An IDE (Integrated Development Environment)
This is where you write and edit your code. Think of it like Microsoft Word for writing essays. VS Code is for writing Python code. An IDE provides a workspace with helpful features like color-coded text, automatic suggestions, and buttons to run your code. While you could write Python in Notepad, an IDE makes coding much more efficient and less error-prone.
Why You Need Both: Python is like the engine of a car. It makes things run. An IDE is like the dashboard and controls. It helps you drive. You can technically write Python code in any text editor (like Notepad), but IDEs provide essential features like syntax highlighting (colors that help you read code), error detection (catching mistakes before you run code), code completion (suggestions as you type), and a run button (executing code with one click). These features make coding WAY easier and help prevent mistakes.
Step 2: Installing Python (Windows & Mac)
Python is completely free and open-source. Install it directly from the official Python website to get the legitimate, up-to-date version.
Always use the official site. It's free, safe, and maintained by the Python Software Foundation.
When you visit the Python downloads page, you'll see a prominent download button that says something like "Download Python 3.12". The website automatically detects your operating system and shows the correct version. Click that button to start the download.
About Python Versions: Python 3.x is the current version (Python 2 is outdated and no longer supported). Any version of Python 3.8 or higher will work perfectly for learning. Don't worry about getting the absolute latest version. Focus on getting Python installed correctly.
Windows Installation Instructions
- Download the installer from python.org. The file will be named something like
python-3.12.x-amd64.exe. - Open the installer by double-clicking the downloaded file. If you see a Windows security warning, click "Yes" or "Run" to proceed.
-
VERY IMPORTANT: On the first screen of the installer, you'll see a checkbox at the bottom that says:
What is PATH? PATH is a list of folders your computer searches when you type commands. By checking this box, you're telling Windows "whenever I type 'python' in the terminal, look for it in the Python installation folder." If you don't check this, you'll have to type the full path to Python every time, which is very inconvenient. Always check this box!
- Click "Install Now" (not "Customize installation". That's for advanced users). The installer will show a progress bar as it installs Python and its components.
- Wait for completion. The installation usually takes 2-5 minutes. When it finishes, you'll see a screen that says "Setup was successful".
- Click "Close". Python is now installed on your computer!
Mac Installation Instructions
- Download the macOS installer from python.org. The file will be a
.pkgfile named something likepython-3.12.x-macos11.pkg. - Open the installer by double-clicking the downloaded
.pkgfile. Your Mac may ask if you're sure you want to open it. Click "Open" to proceed. - Follow the installation wizard. Click "Continue" on each screen to proceed.
- Enter your password. macOS will ask for your administrator password. Type your password and click "Install Software" or "OK".
- Wait for installation. The installation typically takes 2-5 minutes. Don't close the installer window during this time.
- Click "Close" when you see "The installation was successful". Python is now installed on your Mac!
Note for Mac users: On Mac, you'll use python3 (not python) in the terminal. This is because macOS comes with an old version of Python 2 pre-installed, and python3 ensures you're using the new version you just installed.
Python will now be installed on your system.
Step 3: Check if Python Installed Correctly
After installation, verify that Python is working correctly. Open a terminal (also called Command Prompt on Windows) and ask Python to tell us its version number. This confirms that:
- Python is installed
- Your computer can find Python when you type its name
- Python is ready to run code
On Windows:
- Open Command Prompt: Click the Windows search bar or press the Windows key, then type
cmdand press Enter. - Check Python version: In the terminal, type exactly:
python --version(with a space and two dashes before "version"), then press Enter.
On Mac:
- Open Terminal: Press
Cmd + Spaceto open Spotlight search, type "Terminal", and press Enter. - Check Python version: In the terminal window, type exactly:
python3 --version(note: usepython3, notpython), then press Enter.
Python 3.12.1
The exact version number may differ (like 3.11.5 or 3.13.0), but you should see "Python" followed by a version number.
If you see something like "Python 3.12.1", congrats! Python is installed correctly!
This means Python is installed and your computer can find it. You're ready to start coding!
If you see an error like "python is not recognized" or "command not found", Python might not be installed correctly, or it might not be added to your PATH. Try reinstalling Python and make sure to check the "Add Python to PATH" box on Windows.
Mini Practice #1: Test Python Shell
Try It YourselfThe Python shell (also called the Python REPL) is an interactive mode where you can type Python code and see results immediately. This is great for testing small pieces of code. Let's try it:
python
python3
After typing the command and pressing Enter, you should see the Python prompt appear:
>>>
The >>> symbols mean Python is ready and waiting for you to type code. This is called the "Python prompt" or "Python shell". You can now type Python commands directly here. For example, try typing print("Hello!") and pressing Enter. You should see "Hello!" printed below.
To exit the Python shell and return to your regular terminal, type: exit() and press Enter. You'll see the >>> disappear and return to your normal terminal prompt.
Step 4: Install an IDE (We will use VS Code)
While you can write Python code in any text editor, using an IDE (Integrated Development Environment) makes coding much easier and more efficient. An IDE is like a specialized word processor for code. It understands Python syntax and provides helpful features.
We'll use Visual Studio Code (VS Code), which is free, beginner-friendly, and used by millions of developers worldwide. It's made by Microsoft and works on Windows, Mac, and Linux.
Visit the website and click the large download button. The site will automatically detect your operating system and offer the correct version.
After downloading, run the installer and follow the on-screen instructions. The default settings are fine for beginners.
Set Up Python Inside VS Code
VS Code needs a Python extension to understand and run Python code. Extensions are like plugins that add features to VS Code. Here's how to install the Python extension:
Open VS Code
Launch Visual Studio Code from your applications or desktop.
Go to Extensions
Click the Extensions icon in the left sidebar (looks like four squares). Alternatively, press Ctrl+Shift+X (Windows) or Cmd+Shift+X (Mac).
Search for Python
Type "Python" in the search box at the top of the Extensions panel.
Install the Extension
Find the extension called "Python" published by Microsoft. Click the green "Install" button. Once installed, you may need to reload VS Code. If prompted, click "Reload".
What the Python Extension Gives You
The Python extension adds powerful features that make coding easier:
- Syntax highlighting: Your code will be color-coded. Keywords like
printandifappear in different colors, making code easier to read. - Auto-complete: As you type, VS Code will suggest completions. For example, if you type
pr, it might suggestprint. Press Tab to accept suggestions. - Error detection: VS Code will underline mistakes in red before you run your code, helping you catch errors early.
- Run button: A play button (▶) appears in the top-right corner, allowing you to run your Python file with one click instead of typing commands in the terminal.
- Code formatting: Automatically formats your code to look clean and consistent.
These features make coding much easier and help prevent common mistakes!
Mini Practice #2: Your First Python File
Try It YourselfNow let's create your first actual Python file! This is different from the Python shell. A .py file is a saved program that you can run anytime.
In VS Code, follow these steps:
- Create a new file: Click File, then New File (or press
Ctrl+Non Windows /Cmd+Non Mac). - Save the file: Click File, then Save As (or press
Ctrl+S/Cmd+S). Name the filefirst_program.py. The.pyextension tells VS Code this is a Python file. - Type your code: In the editor, type the following code:
To run your code in VS Code: Click the play button (▶) in the top-right corner of VS Code, or right-click in the editor and select "Run Python File in Terminal". You should see "Hello world!" appear in the terminal panel at the bottom of VS Code.
If it worked and printed "Hello world!", congratulations! You've just written and executed your first Python program! You're officially coding! This is the foundation of everything you'll learn: creating files, writing code, and running them to see results.
End-of-Lesson Exercises
Exercise 1: Verify Python Version
This exercise helps you confirm that Python is installed correctly and teaches you how to check version information. This is a useful skill when troubleshooting or working with different Python versions.
Instructions: Open your terminal (Command Prompt on Windows, Terminal on Mac) and type the version command you learned earlier. When you see the version number, write it down in the box below.
Example format: "My Python version is 3.11.4"
This information is useful to know. Some Python features require specific versions, and when asking for help online, people often ask what version you're using.
Exercise 2: Run Your First File
Now you'll create a Python program that prints multiple lines of information about yourself. This exercise teaches you how to use multiple print() statements to display different pieces of information.
Instructions: Create and run a .py file (either in VS Code or using the editor below) that prints three separate lines:
- Your name (replace "Your Name" with your actual name)
- Your favorite hobby or subject
- Why you want to learn Python
Each print() statement creates a new line of output. You can use the editor below to practice, or create a real .py file in VS Code and run it there.
What you should see: When you run the code, each print() statement will output its text on a separate line. Here's an example of what the output might look like:
Adam
I love math and CS.
I want to learn Python to build AI projects!
Success criteria: If you see three separate lines printed (one for your name, one for your hobby/subject, and one for your reason), you've successfully completed this exercise! You've learned how to create a multi-line Python program.