Chapter 0: Environment Setup and Development Tools (Windows, Standard Python)
Table of contents (10)
Language / 语言: English | 中文版
We use two software packages in this course:
- Python (Official Distribution): Provides the Python interpreter and the pip package manager.
- Visual Studio Code (VS Code): A code editor used to write and edit programs.
Version Note (2026-09-08): Current stable Python releases (Python 3.12 and newer) require Windows 10 (version 1809 or newer) or Windows 11, supporting 64-bit x86 and ARM64 architectures. Windows 7 and Windows 8 are no longer supported by recent Python releases. Check the official system requirements before downloading.
Version numbers shown here illustrate output formats; actual numbers may vary. Software menus and button labels may also change over time. Mac users should read the macOS version (Standard Python). If you need an environment configured for data analysis and scientific computing, read the Windows version (Anaconda).
This chapter covers downloading, installing, and configuring both tools on Windows, followed by writing and running your first Python program. After running the program successfully, we examine how these tools work together.
Part 1: Core Track
0.1 Install Official Python
0.1.1 Download the Installer
- Open your browser and visit the official Python download page.
- The website detects Windows and displays the Download Python 3.x.x button.
- Click the button to download the 64-bit installer for Windows (typically named
python-3.12.x-amd64.exe). - If your computer uses an ARM processor, select the Windows installer (ARM64) from the list on the page.
- Record the installer filename and download folder.
0.1.2 Installation Steps
After the download finishes, double-click the .exe installer and follow these steps:
- Setup Wizard and Configuration:
- Inspect the bottom of the installer window.
- Check Add python.exe to PATH. If this option is omitted, typing
pythonin a command terminal will fail because the system cannot find the executable. - Check Use admin privileges when installing py.exe if present.
- Select Installation Mode:
- Install Now installs Python to the default user directory (
C:\Users\username\AppData\Local\Programs\Python\Python3xx). - If your Windows username contains non-ASCII characters, select Customize installation instead, and choose an ASCII path such as
C:\Python312. - Click through to proceed with installation.
- Install Now installs Python to the default user directory (
- Wait for Installation to Complete:
- The wizard installs the Python interpreter, standard library, pip package manager, and documentation.
- This step usually takes one to two minutes.
- Disable Path Length Limit (If Prompted):
- If the final screen displays Disable path length limit, click it to remove the 260-character path limit.
- Confirm the system permission prompt if it appears.
- Close Setup:
- Click Close to exit the installer.
0.1.3 Verify the Installation
After installation, verify that Python and pip run correctly:
Example: Inspect the installed Python and pip version numbers in the Windows terminal.
- Open the Windows Start menu.
- Type
PowerShellorcmdin the search box to open Windows PowerShell or Command Prompt. - At the prompt, enter the following command and press Enter:If the output displays a version string likepowershell
python --versionPython 3.12.x, Python is ready. - Enter the next command and press Enter:If the output displays a string likepowershell
pip --versionpip 24.x.x from ... (python 3.12), pip is functioning properly. - Close the terminal window.
0.2 Install Visual Studio Code
0.2.1 Download the Installer
- Open your browser and visit the VS Code download page.
- Under the Windows logo, click Windows (User Installer) to download the 64-bit installer.
- The downloaded file is typically named
VSCodeUserSetup-x64-1.xx.x.exe.
0.2.2 Installation Steps
Double-click the downloaded setup file and follow the wizard:
- License Agreement: Select "I accept the agreement" and click "Next".
- Destination Location: Keep the default path and click "Next".
- Start Menu Folder: Keep the default and click "Next".
- Select Additional Tasks:
We recommend selecting these options:
- Check Create a desktop icon.
- Check Add "Open with Code" action to Windows Explorer file context menu.
- Check Add "Open with Code" action to Windows Explorer directory context menu.
- Check Register Code as an editor for supported file types.
- Check Add to PATH (requires shell restart) (selected by default). Click "Next".
- Ready to Install: Click "Install" and wait for the files to copy.
- Finish: Check "Launch Visual Studio Code" and click "Finish".
0.3 Initial VS Code Setup
A fresh VS Code installation uses English by default and needs the Python extension. Complete these three configuration steps:
0.3.1 Install Language Pack (Optional)
If you prefer an interface language other than English (such as Simplified Chinese):
- Open VS Code and click the four-square icon in the left activity bar (Extensions, shortcut:
Ctrl + Shift + X). - Type
Chinese(or your preferred language) in the search box. - Find the official language pack published by Microsoft (such as Chinese (Simplified) Language Pack for Visual Studio Code).
- Click Install.
- When prompted in the lower-right corner to "Change Language and Restart", click the button to restart VS Code with the new language.
0.3.2 Install the Python Extension
- Click the Extensions icon in the left activity bar (or press
Ctrl + Shift + X). - In the search box, enter
Python. - Locate the official Python extension published by Microsoft (marked with the blue and yellow Python logo).
- Click Install and wait for the installation to finish.
0.3.3 Select the Official Python Interpreter
Connect VS Code to the installed Python environment:
- Press
Ctrl + Shift + P(or choose "View" -> "Command Palette..." from the top menu) to open the command palette. - Type
Python: Select Interpreterand select the matching command. - VS Code displays the detected Python environments. Select the official Python interpreter, typically located at
...\Programs\Python\Python312\python.exe(or your custom install directory). - After selection, the bottom status bar displays the active environment name, such as
Python 3.12.x 64-bit.
0.4 Write and Run Your First Program
Next, create a dedicated project folder, then save and run your first program.
0.4.1 Create a Working Directory
Keep your course programs in a single folder for organized access.
Example: Create a
python_codefolder, use it to store course files, and open it in VS Code.
- Open File Explorer and create a new folder named
python_codein a directory where you have write permissions. - In VS Code, select File -> Open Folder... from the top menu.
- Select the
python_codefolder and click Select Folder. - When prompted with the dialog asking "Do you trust the authors of the files in this folder?", click Yes, I trust the authors.
0.4.2 Create a Source File
- In the VS Code Explorer sidebar on the left, locate the
PYTHON_CODEfolder header. - Hover over the folder name and click the New File icon (a file icon with a plus sign).
- Type the filename
hello.pyand press Enter. (Python source files use the.pyextension.) - An empty editor tab for
hello.pyopens.
0.4.3 Write and Execute the Code
In the hello.py editor tab, type this line:
Example: Run one line of code to print
Hello, world!to the terminal.
print("Hello, world!")
Press Ctrl + S to save the file. (An unsaved file shows a solid dot next to its filename; saving removes the dot.)
Running the Program (Choose Either Method):
- Method 1 (Recommended): Click the triangular Play button in the upper-right corner of the editor (tooltip: "Run Python File in Dedicated Terminal").
- Method 2: Right-click anywhere in the code editor and choose "Run Python File in Terminal".
VS Code opens an integrated terminal panel at the bottom and prints the output:
Hello, world!
Seeing this text confirms that the Python interpreter executed hello.py successfully. Replace the text inside the quotes with your name, run the file again, and observe the new output.
0.5 Understanding the Tools
0.5.1 The Python Interpreter and pip
The Python interpreter reads and executes Python code. When you ran hello.py, the interpreter executed the print(...) statement and wrote text to the terminal.
The standard Python distribution provides the CPython interpreter maintained by the core Python team. It contains the core language and standard library. The pip tool manages third-party libraries, allowing you to install external packages as needed.
0.5.2 VS Code
VS Code is a code editor. It highlights syntax, suggests autocompletions, and hosts an integrated terminal in one window. With the Python extension installed, it detects interpreters and executes .py files.
0.5.3 From Source File to Program Output
- Save
hello.pyin VS Code. - Trigger "Run Python File in Terminal".
- The selected Python interpreter executes the file.
- The terminal displays the printed results.
Writing code and running code are separate steps. Knowing which file and which interpreter you are running makes it easier to diagnose issues, such as code changes that do not seem to take effect or packages that cannot be found.
Part 2: Supplementary Notes
0.6 Troubleshooting Common Issues (FAQ)
0.6.1 Terminal Error: 'python' is not recognized
- Symptom: Entering
pythonin PowerShell or Command Prompt produces'python' is not recognized as an internal or external command, operable program or batch file. - Cause: The Add python.exe to PATH option was left unchecked during installation. Windows cannot find the Python executable without this path entry.
- Solution (Choose Either Method):
- Method 1 (Recommended): Double-click the downloaded Python setup
.exefile. In the window that appears, select Modify, click Next, and on the "Advanced Options" page, check Add Python to environment variables. Click Install to apply the fix. - Method 2: Use the Python launcher for Windows. Enter
py --versionorpy hello.pyin the terminal. The launcher is usually registered in PATH automatically.
- Method 1 (Recommended): Double-click the downloaded Python setup
0.6.2 Typing 'python' Opens the Microsoft Store
- Symptom: Entering
pythonin the terminal opens the Microsoft Store instead of reporting the Python version. - Cause: Windows 10 and 11 include app execution aliases that redirect to the store when a store package is absent.
- Solution:
- Open Windows Settings (shortcut:
Win + I). - Select Apps -> Advanced app settings -> App execution aliases. (On Windows 10, look near the top of the "Apps & features" page.)
- Locate App Installer (python.exe) and App Installer (python3.exe).
- Toggle both switches to Off.
- Close Settings, open a new terminal, and run
python --versionagain.
- Open Windows Settings (shortcut:
0.6.3 PowerShell Script Execution Policy Error
If the terminal reports that script execution is disabled on this system, the PowerShell execution policy restricts scripts. Run the following command in a standard PowerShell window:
Example: Set the execution policy for the current user so that local environment scripts can run.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
When prompted, type Y and press Enter. Then reopen the VS Code terminal. The -Scope CurrentUser parameter applies only to your account and does not require administrator privileges. If system group policies override this setting, consult the Microsoft execution policy documentation or your lab system administrator.
0.6.4 Missing Run Button or Unselected Interpreter
- Symptom: The triangular run button does not appear in the top-right corner, or a prompt says
Select an Interpreter. - Solution:
- Confirm that the filename ends in
.py. If saved as.txt, VS Code will not activate Python tooling. - Press
Ctrl + Shift + P, typePython: Select Interpreter, and press Enter. - In the list that appears, select the path containing
Python 3.12.
- Confirm that the filename ends in
0.7 Productivity Settings
0.7.1 Enabling Auto Save
Saving files with Ctrl + S before running them is a good habit. The "Run Python File in Terminal" command in the Python extension also saves the active file before execution, though other launch methods may not. See the official run documentation.
To enable Auto Save in VS Code:
- Click File in the top menu bar.
- Select Auto Save.
- VS Code saves dirty files automatically according to its configuration.
0.7.2 Keyboard Shortcuts
| Shortcut | Description |
|---|---|
Ctrl + S |
Save the active file |
Ctrl + / |
Toggle single-line comment (adds or removes #) |
Ctrl + Shift + P |
Open the Command Palette |
Ctrl + B |
Show or hide the primary sidebar |
Ctrl + Backtick |
Show or hide the integrated terminal |
0.8 Basic pip and Python Commands
Most course programs run directly from VS Code. If you want to use the command line, run these commands in PowerShell:
Example: Inspect the list of installed Python libraries in the Windows terminal.
pip list
Common Commands:
python --version: Print the active Python version.pip --version: Print the active pip version.pip list: List all installed third-party packages.pip install package_name: Download and install a package from PyPI.pip install -i https://pypi.tuna.tsinghua.edu.cn/simple package_name: Download using a mirror repository.python: Start the interactive Python shell (typeexit()to quit).python filename.py: Execute a script file directly.
Self-Check
Record your Windows version, the downloaded installer filename, the output of python --version, and the interpreter path. Check the official documentation to confirm that the installer matches your system architecture. Then modify the printed text in hello.py and run it again.
Navigation: Course overview (Chinese) | Next: Chapter 1 Basic Data Types and Operations (Chinese)
The English version of Chapter 1 is not yet available.