uv包简单使用案例
uv由Charlie Marsh开发,是Astral Tool的一个快速Python包安装器和解析器。它类似于pip和pip-tools,但速度更快。此外,uv还支持虚拟环境管理,替代venv和virtualenv。
参考:https://github.com/astral-sh/uv
安装:
# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows.
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# With pip.
pip install uv
安装python虚拟环境
# 创建虚拟环境(替代 python -m venv)
uv venv myenv
# 激活虚拟环境(Linux/macOS)
source myenv/bin/activate
# 在虚拟环境中安装包
uv pip install --python=3.11 flask # 指定 Python 版本
# 退出环境,在 CMD/PowerShell 中
deactivate
windows激活环境
# 进入虚拟环境目录的 Scripts 文件夹
cd myenv\Scripts
# 执行激活命令
activate.bat
# 或直接通过完整路径激活
myenv\Scripts\activate.bat
安装包
# 安装单个包(比 pip 快 10-100 倍)
uv pip install numpy
# 安装多个包
uv pip install pandas matplotlib scikit-learn
# 安装指定版本的包
uv pip install "requests>=2.26,<3.0"