python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
导出依赖
pip freeze > requirements.txt
退出
deactivate
注意
.venv目录不要提交到 git,写进.gitignore- 不同项目的 venv 互相独立,别在系统 Python 里装包
- 用
python -m pip而不是直接pip,避免装到错误的环境
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip freeze > requirements.txt
deactivate
.venv 目录不要提交到 git,写进 .gitignorepython -m pip 而不是直接 pip,避免装到错误的环境