uv(Python包管理器)简介
uv是一个免费的Python包管理器,基于Rust编写,可以作为Python包管理器pip的替代品,旨在构建快速、可靠且易于使用的全面Python项目和包管理器,该工具相对而言更加专注于性能,相比于没有缓存时的pip和pip-tools,它的速度提高了8-10倍,而在使用缓存时,速度提高了80-115倍。
uv利用全局模块缓存来避免重复下载和构建依赖项,并在支持的文件系统上利用写时复制和硬链接来最小化磁盘空间使用,它支持Linux、Windows和macOS。
uv(Python包管理器)官网及教程
- 官网:https://astral.sh/blog/uv
- Github项目开源主页:https://github.com/astral-sh/uv
- 官网最新版本:https://github.com/astral-sh/uv/releases
独立安装程序或 PyPI进行安装:
# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows.
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# With pip.
pip install uv
# With pipx.
pipx install uv
# With Homebrew.
brew install uv
# With Pacman.
pacman -S uv
创建虚拟环境:
uv venv # Create a virtual environment at .venv.
激活虚拟环境:
# On macOS and Linux.
source .venv/bin/activate
# On Windows.
.venv\Scripts\activate
将软件包安装到虚拟环境中:
uv pip install flask # Install Flask.
uv pip install -r requirements.txt # Install from a requirements.txt file.
uv pip install -e . # Install the current project in editable mode.
uv pip install "package @ ." # Install the current project from disk
uv pip install "flask[dotenv]" # Install Flask with "dotenv" extra.
从输入文件生成一组锁定的依赖项:
uv pip compile pyproject.toml -o requirements.txt # Read a pyproject.toml file.
uv pip compile requirements.in -o requirements.txt # Read a requirements.in file.
将一组锁定的依赖项与虚拟环境同步:
uv pip sync requirements.txt # Install from a requirements.txt file.