Python虚拟环境创建及使用

Sunmy Lv5

安装虚拟环境

1
2
sunmy@LDSPDVS:~$ sudo apt update
sunmy@LDSPDVS:~$ sudo apt install python3.12-venv

创建虚拟环境

1
sunmy@LDSPDVS:~$ python3 -m venv VenvPython  # VenvPython 环境名称

激活虚拟环境

1
2
sunmy@LDSPDVS:~$ source ./VenvPython/bin/activate
(VenvPython) sunmy@LDSPDVS:~$

安装依赖包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(VenvPython) sunmy@LDSPDVS:~$ pip install pytest
Collecting pytest
Downloading pytest-8.3.5-py3-none-any.whl.metadata (7.6 kB)
Collecting iniconfig (from pytest)
Downloading iniconfig-2.1.0-py3-none-any.whl.metadata (2.7 kB)
Collecting packaging (from pytest)
Downloading packaging-25.0-py3-none-any.whl.metadata (3.3 kB)
Collecting pluggy<2,>=1.5 (from pytest)
Downloading pluggy-1.6.0-py3-none-any.whl.metadata (4.8 kB)
Downloading pytest-8.3.5-py3-none-any.whl (343 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 343.6/343.6 kB 1.2 MB/s eta 0:00:00
Downloading pluggy-1.6.0-py3-none-any.whl (20 kB)
Downloading iniconfig-2.1.0-py3-none-any.whl (6.0 kB)
Downloading packaging-25.0-py3-none-any.whl (66 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 66.5/66.5 kB 16.1 MB/s eta 0:00:00
Installing collected packages: pluggy, packaging, iniconfig, pytest
Successfully installed iniconfig-2.1.0 packaging-25.0 pluggy-1.6.0 pytest-8.3.5
(VenvPython) sunmy@LDSPDVS:~$
(VenvPython) sunmy@LDSPDVS:~$ pip list
Package Version
--------- -------
iniconfig 2.1.0
packaging 25.0
pip 24.0
pluggy 1.6.0
pytest 8.3.5
(VenvPython) sunmy@LDSPDVS:~$

退出虚拟环境

1
2
VenvPython) sunmy@LDSPDVS:~$ deactivate
sunmy@LDSPDVS:~$
  • 标题: Python虚拟环境创建及使用
  • 作者: Sunmy
  • 创建于 : 2025-05-31 11:37:52
  • 更新于 : 2025-06-29 21:05:24
  • 链接: https://ldspdvsun.github.io/cmchvp8g50037h0gba8f12pxv/
  • 版权声明: 版权所有 © Sunmy,禁止转载。
评论