VSCode + Python Development Environment Configuration Guide
This article introduces how to configure the Python development environment on Windows, including Python interpreter installation, VSCode editor configuration, and the use of package management tools.
1. Install Python
Download Python
- Visit the Python official website: https://www.python.org/downloads/
- Click the "Download Python" button to download the latest version.
- Or select a specific version at the bottom of the page (3.10 or higher is recommended).
Install Python
- Run the downloaded installer.
- Important: Check the "Add Python to PATH" option.
- Click "Install Now" to install with default settings.
- Wait for the installation to complete.
Verify Installation
Open the Command Prompt (Press Win+R, type cmd, and press Enter), then execute:
python --version
If the Python version number is displayed, the installation is successful. Type exit() to exit the Python interactive mode.
Manual Environment Variable Configuration (Optional)
If "Add Python to PATH" was not checked during installation, you need to configure it manually:
- Press
Win+Sand search for "Environment Variables". - Click "Edit the system environment variables".
- Click the "Environment Variables" button.
- Find
Pathin "User variables" or "System variables". - Click "Edit" and add the following paths (adjust based on actual installation path):
C:\Users\YourUsername\AppData\Local\Programs\Python\Python3x\C:\Users\YourUsername\AppData\Local\Programs\Python\Python3x\Scripts\
2. Install VSCode
- Visit the VSCode official website: https://code.visualstudio.com/download
- Select the Windows version to download.
- Run the installer and follow the default settings to complete the installation.
3. Configure VSCode Python Extension
Install Python Extension
- Open VSCode.
- Press
Ctrl+Shift+Xto open the Extensions Marketplace. - Search for "Python".
- Install the official Python extension provided by Microsoft.
Select Python Interpreter
- Press
Ctrl+Shift+Pto open the Command Palette. - Type "Python: Select Interpreter".
- Select your installed Python version.
Run Python Code
Method 1: Use the Run button
- Open a Python file and click the Run button in the top right corner.
Method 2: Use the Context Menu
- Right-click in the editor and select "Run Python File in Terminal".
Method 3: Use Shortcut Keys
- Press
Ctrl+F5to run the current file directly.
4. Use pip to Install Third-party Libraries
Python's power lies in its rich ecosystem of third-party libraries. Use the pip command to install the required libraries.
Basic Usage
# Install a library
pip install library_name
# Install a specific version
pip install library_name==version_number
# Upgrade a library
pip install --upgrade library_name
# Uninstall a library
pip uninstall library_name
# View installed libraries
pip list
Install Qiaotong Library
pip install qtmodel
Configure Mirror Source (For Users in China)
The default PyPI source may be slow in China. Configure a mirror:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Other Common Mirror Sources
| Mirror Source | Address |
|---|---|
| Tsinghua | https://pypi.tuna.tsinghua.edu.cn/simple |
| Aliyun | https://mirrors.aliyun.com/pypi/simple |
| USTC | https://pypi.mirrors.ustc.edu.cn/simple |