pythonic生物人

conda太慢了,Python生态管理神器uv真快!

2026年3月19日,OpenAI把Astral收购了,并入Codex团队,继续支持Astral旗下Python工具开源!

Image

说起Astral,很多人可能不熟悉,但是,该团队开发的开源Python工具uv等,每月下载量上亿次。

Image
本文重点介绍一下uv,有人甚至说它是近10年来Python生态最好管理神器!
Image

uv是新一代Python package/环境/项目等管理神器,可解决pip、conda、virtualenv等的龟速、低效,速度是extremely fast。

Image

以mac/linux系统为例,介绍uv的功能。

  • uv安装
pip install uv -i https://pypi.tuna.tsinghua.edu.cn/simple/
Image
  • uv作用速览
  auth     Manage authentication
  run      Run a command or script
  init     Create a new project
  add      Add dependencies to the project
  remove   Remove dependencies from the project
  version  Read or update the project's version
  sync     Update the project'
s environment
  lock     Update the project's lockfile
  export   Export the project'
s lockfile to an alternate format
  tree     Display the project's dependency tree
  format   Format Python code in the project
  audit    Audit the project'
s dependencies
  tool     Run and install commands provided by Python packages
  python   Manage Python versions and installations
  pip      Manage Python packages with a pip-compatible interface
  venv     Create a virtual environment
  build    Build Python packages into source distributions and wheels
  publish  Upload distributions to an index
  cache    Manage uv's cache
  self     Manage the uv executable
  help     Display documentation for a command
  • uv查看可用版本python(包含未安装的版本)
uv python list
Image
  • uv安装指定版本python
# uv安装python 3.8
uv python install 3.8

uv python list查看一下安装的路径,

Image
但是,uv貌似不支持3.8版本前的Python。
Image

  • uv删除指定版本python
uv python uninstall 3.8 
Image

速度很快。

  • uv查看已安装版本python
uv python list --only-installed
Image
  • uv同时安装多个版本python
uv python install 3.12 3.13 3.14
  • uv使用指定版本python

用python3.8运行test.py脚本

uv run python3.8 test.py
Image

很方便,不需要调用激活环境,也不需要python3.8的绝对路径。

  • uv打开指定版本python终端
# 打开python3.8
uv run python3.8
Image
  • uv构建环境
# 构建名称为test_env的环境,python版本为3.8
uv venv test_env -p 3.8

# 激活test_env环境
source test_env/bin/activate

# 退出环境

deactivate

Image

如果指定的python3.8之前已经安装过,不会再次安装,否则,会直接安装python3.8。

构建成功后当前文件下有一个test_env环境文件夹。

  • uv安装python包
# 安装matplotlib
uv pip install matplotlib
Image
  • uv卸载python包
uv pip uninstall matplotlib
Image
  • uv批量安装python包
# requirements.txt为各种包文件
uv pip install -r requirements.txt

#requirements.txt格式
pymupdf==1.18.14
xlsxwriter==1.3.7
openpyxl==3.0.5
pandas==1.1.3
numpy==1.19.2
matplotlib==3.3.2

用法和pip类似,只是前面加了uv。

  • uv管理项目依赖、环境

和rye、poetry等类似。

$ uv init example
Initialized project `example` at `/home/user/example`

$ cd example

$ uv add ruff
Creating virtual environment at: .venv
Resolved 2 packages in 170ms
   Built example @ file:///home/user/example
Prepared 2 packages in 627ms
Installed 2 packages in 1ms
 + example==0.1.0 (from file:///home/user/example)
 + ruff==0.5.0

$ uv run ruff check
All checks passed!

$ uv lock
Resolved 2 packages in 0.33ms

$ uv sync
Resolved 2 packages in 0.70ms
Checked 1 package in 0.02ms
  • uv安装command-line tools
# 安装ruff
uv tool install ruff
  • uv使用command-line tools
uvx pycowsay 'hello world!'
#或
uv tool run pycowsay 'hello world!'
Image

来源:https://github.com/astral-sh/uv


一些有用的:

👉2026可视化工具TOP3

👉学习R可视化

👉Python matplotlib

👉嫌Matplotlib繁琐?试试Seaborn

(学习了,备注:299)

图片