有一个选择:
--system-site-packages
Give the virtual environment access to the system
site-packages dir.
所以如果你使用
python3 -m venv --system-site-packages .venv
然后,您可以在系统级别安装所有环境可用的软件包。你必须对系统级安装的软件包保持卫生。
如果您发行版上的系统python非常混乱,并且您无法从中删除不希望在venvs中可见的内容,那么您需要寻找另一个选项。
一种可能是将通用软件包安装到某个目标目录:
python3 -m pip install dep1 dep2 --target=/path/to/common
然后使包目录始终可见:
export PYTHONPATH=/path/to/common