[英]How does pip3 knows it should install packages into the virtual environment, when using symlinks rather than copies?
pip3 install
或python3 -m pip install
如何知道它应该将包安装到虚拟环境的lib/python3.8/site-packages
目录中?
特别是, python3
的符号链接如下:
$ ls -la bin/python3
lrwxr-xr-x 1 admin staff 22B Jun 23 14:07 bin/python3@ -> /usr/local/bin/python3
我考虑过VIRTUAL_ENV
环境变量,但取消设置它似乎并没有改变pip3
行为方式。
有谁知道?
阅读由 venv 创建的 shell 脚本activate
的代码,我注意到它不只是设置VIRTUAL_ENV
环境变量。 它还设置PS1
和PATH
。
它还PYTHONHOME
。 所以我会说组合就是做这项工作的原因。
查看脚本的相关位:
VIRTUAL_ENV="/path/to/venv"
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH
# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
unset PYTHONHOME
fi
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
if [ "x(env) " != x ] ; then
PS1="(env) ${PS1:-}"
else
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
else
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
fi
fi
export PS1
fi
不是pip
— 是python
知道目录在哪里:
$ python -c "import sys; print(sys.prefix)"
/home/phd/.local
$ ~/.virtualenvs/ansible/bin/python -c "import sys; print(sys.prefix)"
/home/phd/.virtualenvs/ansible
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.