且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python:使用 venv 来创建虚拟环境

更新时间:2022-08-22 14:37:16

Python文档有如下的介绍:

Python 在 3.5 版更改: 现在推荐使用 venv 来创建虚拟环境

# 创建名为 .venv 的虚拟环境
python3 -m venv .venv

# 激活虚拟环境
source .venv/bin/activate

# 退出虚拟环境
deactivate

查看当前目录的文件

$ tree -a
.
└── .venv
    ├── bin
    │   ├── activate
    │   ├── activate.csh
    │   ├── activate.fish
    │   ├── python -> python3
    │   └── python3 -> /Users/.pyenv/versions/py370/bin/python3
    ├── include
    ├── lib
    │   └── python3.7
    │       └── site-packages
    └── pyvenv.cfg

参考

https://docs.python.org/zh-cn/3/library/venv.html