Configuration of Python Development Environment
Configuring a development environment on a new machine requires establishing a reliable network connection, setting up a modern shell, and installing a robust editor and package manager. This guide follows a bottom-up approach: Network/Shell -> Editor -> Runtime.
1. PowerShell & Network Access
Network Pre-requisites:
Before configuring the software, ensure your network environment is ready.
- Proxy Setup: Use tools like Clash or similar applications to handle proxy settings.
- GitHub Access: Tools like Watt Toolkit can facilitate access to GitHub if direct connection is unstable.
- Package Manager: Ensure
wingetis installed and functional.
PowerShell Setup:
- Version Check: Verify if
wingetis operational.- If functional ->
winget search --id Microsoft.PowerShell - If not -> Visit the Microsoft PowerShell website, download the
.msipackage, and install manually. - Update: Run As Administrator >
Install-Module -Name Microsoft.WinGet.Client -Force -Repository PSGalleryRepair-WinGetPackageManager -AllUsersr
- If functional ->
Configuration Profile:
To enhance the shell experience with intelligent auto-completion and proxy aliases, configure the profile as follows:
- Install Modules:
Install-Module PSReadLine -Force -AllowClobber(Adds Intellisense). - Create Profile:
New-Item –Path $Profile –Type File –Force. - Edit:
notepad $Profile.
Add the following configuration to handle Intellisense and Proxy Switching logic:
# powershell settings
# intellisense
Set-PSReadLineKeyHandler -Key Tab -Function AcceptSuggestion
# proxy configuration
# Manual Function
function proxy {
# Set HTTP and HTTPS proxies
$env:HTTP_PROXY = "http://127.0.0.1:7890"
$env:HTTPS_PROXY = "http://127.0.0.1:7890"
$env:ALL_PROXY = "socks5://127.0.0.1:7890"
Write-Host " Proxy ON at 127.0.0.1:7890" -ForegroundColor Green
}
function unproxy {
$env:HTTP_PROXY = ""
$env:HTTPS_PROXY = ""
$env:ALL_PROXY = ""
Write-Host " Proxy OFF" -ForegroundColor Yellow
}
# System Proxy Auto-Detection
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$proxyEnable = (Get-ItemProperty -Path $regPath).ProxyEnable
$proxyServer = (Get-ItemProperty -Path $regPath).ProxyServer
if ($proxyEnable -eq 1) {
if ($proxyServer -match "(\d+\.\d+\.\d+\.\d+:\d+)") {
$proxyAddress = "http://" + $matches[1]
$env:HTTP_PROXY = $proxyAddress
$env:HTTPS_PROXY = $proxyAddress
$env:ALL_PROXY = $proxyAddress
Write-Host " Proxy Detected & Enabled: $proxyAddress" -ForegroundColor Cyan
}
}
2. VS Code
Installation:
- Download from the official VS Code website.
- Note: Ensure all context menu options (e.g., "Open with Code") are checked during installation.
Extensions:
Essential plugins for a Python workflow:
- Core: Git Extension Pack, Python Extension Pack.
- UI/UX: Github Theme, Material Icon Theme, PowerShell.
- Utilities: Markdown Preview Enhanced.
- Language: Chinese LanguagePack (Optional).
Git install:
- go to its website and flow or just
winget install --id Git.Git -e --source winget- set git account
git config --global user.name "Your Name"git config --global user.email "your_email@example.com"- set git proxy like
git config --global http.proxy http://127.0.0.1:7890git config --global https.proxy http://127.0.0.1:7890
Font Configuration:
- Recommendation: JetBrains Mono.
- Installation: Download from the official site -> Extract -> Install
.ttffiles (Bold, Regular, Italic, etc.) viafonts\ttf\. - Config: In VS Code settings, search for "Font Family" and edit:
JetBrains Mono, monospace
3. Python Runtime
1 Conda (Environment Management)
Conda is robust for managing complex dependencies and creating isolated environments.
- Installation: Download Miniconda (preferred for lightweight setup), check all installation options, and run
conda initin PowerShell. - Common Commands:
conda env list: View all environments.conda activate <envname>: Switch context to a specific environment.conda install python=<version>: Update the Python version in the base environment.- [to modify the file path for new envs, edit
.condarcunder your conda folder] - add your path like:
envs_dirs:
- C:\Coding\Envs\envs
pkgs_dirs:
- C:\Coding\Envs\pkgs
* then make sure the user has permisson to your envs folder (you can right click it open Properties and change it in safety)
2 uv (Package Management)
uv is a modern, extremely fast Python package installer and resolver, written in Rust. It is the suggested tool for package installation.
- Installation:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
- Usage:
uv pip install <module>: Install packages rapidly.
- Troubleshooting:
- If you encounter the error
No virtual environment found, append the following environment variable to your PowerShell profile: $Env:UV_SYSTEM_PYTHON = 1