Skip to content

Commit a0a953e

Browse files
committed
新增uv环境管理
1 parent 2d34a68 commit a0a953e

4 files changed

Lines changed: 91 additions & 0 deletions

File tree

docs/chapter1/04_virtualenv.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# 附:Python虚拟环境部署方案补充:uv 环境管理
2+
3+
本项目由于涉及到的包过多,并且**依赖问题**自始至终都是Python的老大难问题,这就造成了 Python 工程化方面生态非常割裂。
4+
5+
对于这种问题,uv提供了统一的虚拟环境管理入口,同时吸收了 Rust 语言先进的包管理经验,使用它可以减少我们在 Python 工程方面折腾的时间,下面我们使用uv来安装项目的虚拟环境。
6+
7+
## 1.1 安装uv
8+
9+
### 1.1.1 Windows 系统
10+
11+
**使用powershell 安装 uv**
12+
13+
```bash
14+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
15+
```
16+
17+
**安装成功后,按照提示输入以下命令添加环境变量**。这里注意,**不同的人的安装路径不同**,请按照提示自行复制粘贴命令。
18+
19+
20+
```bash
21+
$env:Path = "C:\Users\michaelbradley\.local\bin;$env:Path"
22+
```
23+
24+
![安装成功的提示](./images/1_4_1.png)
25+
26+
27+
**输入 uv 命令,如果出现以下提示,说明安装成功**
28+
29+
![成功安装uv](./images/1_4_2.png)
30+
31+
### 1.1.2 Linux / MacOS 系统
32+
33+
**使用 curl 安装 uv**
34+
35+
```bash
36+
curl -LsSf https://astral.sh/uv/install.sh | sh
37+
```
38+
39+
如果无法使用 curl 命令,**使用 wget 命令**安装 uv
40+
41+
```bash
42+
wget -qO- https://astral.sh/uv/install.sh | sh
43+
```
44+
45+
**输入 uv 命令,如果出现以下提示,说明安装成功**
46+
47+
![成功安装uv](./images/1_4_3.png)
48+
49+
50+
## 1.2 创建并激活虚拟环境
51+
52+
### 1.2.1 **创建虚拟环境**
53+
54+
```bash
55+
uv venv rag --python 3.12.7
56+
```
57+
58+
代码创建的虚拟环境名称为 rag ,使用Python版本为 3.12.7
59+
60+
Windows 系统创建成功后显示如下信息:
61+
62+
```bash
63+
PS C:\Users\parallel> uv venv rag --python 3.12.7
64+
Using CPython 3.12.7
65+
Creating virtual environment at: rag
66+
Activate with: rag\Scripts\activate
67+
```
68+
69+
Linux / MacOS 系统创建成功后显示如下信息:
70+
71+
```bash
72+
┌──(parallel㉿pacman)-[~/桌面]
73+
└─$ uv venv rag -p 3.12.7
74+
Using CPython 3.12.7
75+
Creating virtual environment at: rag
76+
Activate with: source rag/bin/activate
77+
```
78+
79+
### 1.2.2 **激活虚拟环境**
80+
81+
Windows 系统激活虚拟环境命令为:
82+
83+
```bash
84+
rag\Scripts\activate
85+
```
86+
87+
Linux / MacOS 系统激活虚拟环境命令为:
88+
89+
```bash
90+
source rag/bin/activate
91+
```

docs/chapter1/images/1_4_1.png

72.1 KB
Loading

docs/chapter1/images/1_4_2.png

108 KB
Loading

docs/chapter1/images/1_4_3.png

947 KB
Loading

0 commit comments

Comments
 (0)