uv入门教程示例
·
1. 安装uv
GitHub: https://github.com/astral-sh/uv
macOS/Linux:
# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh
2. 初始化项目
2.1. 语法
uv init <项目名称>
2.2. 示例
uv init mcpTest
执行命令后,会在当前目录中创建名为mcpTest的文件夹
3. 创建虚拟环境
3.1. 查看uv支持的python版本
cpython-3.14.0rc1-linux-x86_64-gnu <download available>
cpython-3.14.0rc1+freethreaded-linux-x86_64-gnu <download available>
cpython-3.13.5-linux-x86_64-gnu <download available>
cpython-3.13.5+freethreaded-linux-x86_64-gnu <download available>
cpython-3.12.11-linux-x86_64-gnu <download available>
........
3.2. 安装指定版本的python
3.2.1. 语法
uv python install <python版本>
3.2.2. 示例
uv python install cpython-3.12.11-linux-x86_64-gnu
3.3. 切换到指定版本
3.3.1. 语法
uv python pin <python版本>
3.3.2. 示例
uv python pin 3.12
3.3.3. 输出示例
➜ mcpTest git:(master) ✗ uv python pin 3.12
Updated `.python-version` from `3.11` -> `3.12`
3.4. 创建虚拟环境
3.4.1. 语法
uv venv
执行命令后,会在本地创建.venv
3.5. 激活虚拟环境
macOS/Linux
source .venv/bin/activate
4. 安装依赖
4.1. 语法
uv add <依赖名>
4.2. 示例
uv add "mcp[cli]"
4.3. 输出示例
warning: `VIRTUAL_ENV=/root/mcpSearch/mcp/.venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
Using CPython 3.11.13
Creating virtual environment at: .venv
Resolved 35 packages in 392ms
Prepared 23 packages in 238ms
Installed 32 packages in 31ms
+ annotated-types==0.7.0
+ anyio==4.10.0
+ attrs==25.3.0
+ certifi==2025.8.3
....
更多推荐


所有评论(0)