Skip to content

Chapter 0: Environment Setup and Development Tools (Windows, Standard Python)

Updated: 2026-09-08 19:10 · English
Table of contents (10)

Language / 语言: English | 中文版

We use two software packages in this course:

  1. Python (Official Distribution): Provides the Python interpreter and the pip package manager.
  2. 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

  1. Open your browser and visit the official Python download page.
  2. The website detects Windows and displays the Download Python 3.x.x button.
  3. Click the button to download the 64-bit installer for Windows (typically named python-3.12.x-amd64.exe).
  4. If your computer uses an ARM processor, select the Windows installer (ARM64) from the list on the page.
  5. 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:

  1. Setup Wizard and Configuration:
    • Inspect the bottom of the installer window.
    • Check Add python.exe to PATH. If this option is omitted, typing python in a command terminal will fail because the system cannot find the executable.
    • Check Use admin privileges when installing py.exe if present.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

  1. Open the Windows Start menu.
  2. Type PowerShell or cmd in the search box to open Windows PowerShell or Command Prompt.
  3. At the prompt, enter the following command and press Enter:
    powershell
    python --version
    
    If the output displays a version string like Python 3.12.x, Python is ready.
  4. Enter the next command and press Enter:
    powershell
    pip --version
    
    If the output displays a string like pip 24.x.x from ... (python 3.12), pip is functioning properly.
  5. Close the terminal window.

0.2 Install Visual Studio Code

0.2.1 Download the Installer

  1. Open your browser and visit the VS Code download page.
  2. Under the Windows logo, click Windows (User Installer) to download the 64-bit installer.
  3. 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:

  1. License Agreement: Select "I accept the agreement" and click "Next".
  2. Destination Location: Keep the default path and click "Next".
  3. Start Menu Folder: Keep the default and click "Next".
  4. 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".
  5. Ready to Install: Click "Install" and wait for the files to copy.
  6. 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):

  1. Open VS Code and click the four-square icon in the left activity bar (Extensions, shortcut: Ctrl + Shift + X).
  2. Type Chinese (or your preferred language) in the search box.
  3. Find the official language pack published by Microsoft (such as Chinese (Simplified) Language Pack for Visual Studio Code).
  4. Click Install.
  5. 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

  1. Click the Extensions icon in the left activity bar (or press Ctrl + Shift + X).
  2. In the search box, enter Python.
  3. Locate the official Python extension published by Microsoft (marked with the blue and yellow Python logo).
  4. 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:

  1. Press Ctrl + Shift + P (or choose "View" -> "Command Palette..." from the top menu) to open the command palette.
  2. Type Python: Select Interpreter and select the matching command.
  3. 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).
  4. 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_code folder, use it to store course files, and open it in VS Code.

  1. Open File Explorer and create a new folder named python_code in a directory where you have write permissions.
  2. In VS Code, select File -> Open Folder... from the top menu.
  3. Select the python_code folder and click Select Folder.
  4. 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

  1. In the VS Code Explorer sidebar on the left, locate the PYTHON_CODE folder header.
  2. Hover over the folder name and click the New File icon (a file icon with a plus sign).
  3. Type the filename hello.py and press Enter. (Python source files use the .py extension.)
  4. An empty editor tab for hello.py opens.

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.

python
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:

text
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

  1. Save hello.py in VS Code.
  2. Trigger "Run Python File in Terminal".
  3. The selected Python interpreter executes the file.
  4. 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 python in 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 .exe file. 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 --version or py hello.py in the terminal. The launcher is usually registered in PATH automatically.

0.6.2 Typing 'python' Opens the Microsoft Store

  • Symptom: Entering python in 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:
    1. Open Windows Settings (shortcut: Win + I).
    2. Select Apps -> Advanced app settings -> App execution aliases. (On Windows 10, look near the top of the "Apps & features" page.)
    3. Locate App Installer (python.exe) and App Installer (python3.exe).
    4. Toggle both switches to Off.
    5. Close Settings, open a new terminal, and run python --version again.

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.

powershell
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:
    1. Confirm that the filename ends in .py. If saved as .txt, VS Code will not activate Python tooling.
    2. Press Ctrl + Shift + P, type Python: Select Interpreter, and press Enter.
    3. In the list that appears, select the path containing Python 3.12.

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:

  1. Click File in the top menu bar.
  2. Select Auto Save.
  3. 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.

powershell
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 (type exit() 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.