uv

uv 是一个用rust编写的python版本管理器,优点主要是下载依赖包速度非常快。

下载安装 uv

1
2
# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh
1
2
# On Windows.
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

uv自动更新

1
uv self update

使用方法

首先使用

1
uv init

初始化一个环境

然后可以使用uv安装多个需要的python版本

1
uv python install python 3.10 3.11 3.12

在工作目录里固定python版本

1
uv python pin 3.11

创建虚拟环境

1
uv venv

进入虚拟环境

1
2
# linux
source .venv/bin/activate

添加依赖环境

1
uv add numpy scipy

当然也可以复用原来的命令

1
uv pip install -r requirement.txt

这样会把原来的依赖更新到pyproject.toml中

运行脚本使用

1
uv run example.py # 示例