Python 开发环境

最佳实践 3 分钟阅读 更新于 2024-11-09

1. Overview

Windows Linux/WSL

2. Windows

使用 uv 管理python版本和虚拟环境

2.1. uv

1
2
3
4
5
6
7
8
9
10
11
12
# Install uv
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

# Upgrading uv
uv self update

# Add shell autocompletion
Add-Content -Path $PROFILE -Value @'
# uv
(& uv generate-shell-completion powershell) | Out-String | Invoke-Expression

'@

2.2. python

1
2
3
4
5
6
7
8
9
10
11
12
# list all available Python versions
uv python list

# install a Python version
uv python install 3.12

# set uv pip install mirror
Add-Content -Path $env:APPDATA\uv\uv.toml -Value @'
[[index]]
url = "https://mirrors.aliyun.com/pypi/simple"
default = true
'@

3. Linux/WSL

使用 uv 管理python版本和虚拟环境

3.1. uv

1
2
3
4
5
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Upgrading uv
uv self update

3.2. python

1
2
3
4
5
6
7
8
# use  **bash** !!

# set uv pip install mirror
cat > ~/.config/uv/uv.toml <<- 'EOM'
[[index]]
url = "https://mirrors.aliyun.com/pypi/simple"
default = true
EOM
1
2
3
4
5
# list all available Python versions
uv python list

# install a Python version
uv python install 3.12

如果这篇文章对您有帮助,欢迎打赏支持