UV使用

394 字
2 分钟
UV使用

从 micromamba 转 uv 了

UV 优势#

安装#

Terminal window
# 安装
brew install uv
# mise
# mise use -g uv@latest

配置镜像源#

$XDG_CONFIG_HOME/uv/uv.toml

[[index]]
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/"
default = true

迁移micromanba#

Terminal window
# 迁移 micromamba 到 uv
micromamba list -e > requirements.txt
uv pip install -r requirements.txt

使用#

Terminal window

Python versions#

  • uv python install: Install Python versions.
  • uv python list: View available Python versions.
  • uv python find: Find an installed Python version.
  • uv python pin: Pin the current project to use a specific Python version.
  • uv python uninstall: Uninstall a Python version.

Scripts#

  • uv run: Run a script.
  • uv add --script: Add a dependency to a script
  • uv remove --script: Remove a dependency from a script

Projects#

  • uv init: Create a new Python project.
  • uv add: Add a dependency to the project.
  • uv remove: Remove a dependency from the project.
  • uv sync: Sync the project’s dependencies with the environment.
  • uv lock: Create a lockfile for the project’s dependencies.
  • uv run: Run a command in the project environment.
  • uv tree: View the dependency tree for the project.
  • uv build: Build the project into distribution archives.
  • uv publish: Publish the project to a package index.

Tools#

  • uvx / uv tool run: Run a tool in a temporary environment.
  • uv tool install: Install a tool user-wide.
  • uv tool uninstall: Uninstall a tool.
  • uv tool list: List installed tools.
  • uv tool update-shell: Update the shell to include tool executables.

The pip interface#

  • uv venv: Create a new virtual environment.
  • uv pip install: Install packages into the current environment.
  • uv pip show: Show details about an installed package.
  • uv pip freeze: List installed packages and their versions.
  • uv pip check: Check that the current environment has compatible packages.
  • uv pip list: List installed packages.
  • uv pip uninstall: Uninstall packages.
  • uv pip tree: View the dependency tree for the environment.
  • uv pip compile: Compile requirements into a lockfile.
  • uv pip sync: Sync an environment with a lockfile.

Utility#

  • uv cache clean: Remove cache entries.
  • uv cache prune: Remove outdated cache entries.
  • uv cache dir: Show the uv cache directory path.
  • uv tool dir: Show the uv tool directory path.
  • uv python dir: Show the uv installed Python versions path.
  • uv self update: Update uv to the latest version.

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

UV使用
https://blog.sephy.top/posts/uv使用/
作者
虾米
发布于
2025-05-22
许可协议
CC BY-NC-SA 4.0
随机文章随机推荐
Profile Image of the Author
虾米
coder
分类
标签
站点统计
文章
61
分类
4
标签
52
总字数
64,663
运行时长
0
最后活动
0 天前
站点信息
构建平台
GitHub Actions
博客版本
Firefly v6.13.9
文章许可
CC BY-NC-SA 4.0