Linux command
venv 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Create virtual environment
python -m venv [venv]
Create with system packages
python -m venv --system-site-packages [venv]
Activate (bash/zsh)
source [venv]/bin/activate
Activate (fish)
source [venv]/bin/activate.fish
Deactivate
deactivate
Clear environment
python -m venv --clear [venv]
说明
venv creates lightweight Python virtual environments that isolate project dependencies from the system Python installation. Each virtual environment has its own site-packages directory and can have different versions of packages installed without conflicts. The module is part of the Python standard library and requires no additional installation. Activation scripts modify the shell's PATH to use the virtual environment's Python and pip, and deactivate returns to the system environment.
参数
- --system-site-packages
- Include system packages.
- --clear
- Clear existing.
- --without-pip
- Don't install pip.
- --upgrade
- Upgrade scripts.
- --prompt _TEXT_
- Custom prompt.
FAQ
What is the venv command used for?
venv creates lightweight Python virtual environments that isolate project dependencies from the system Python installation. Each virtual environment has its own site-packages directory and can have different versions of packages installed without conflicts. The module is part of the Python standard library and requires no additional installation. Activation scripts modify the shell's PATH to use the virtual environment's Python and pip, and deactivate returns to the system environment.
How do I run a basic venv example?
Run `python -m venv [venv]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --system-site-packages do in venv?
Include system packages.