为什么我的 venv 使用的 pip 版本与我安装的版本不同 [英] Why is my venv using a different pip version than I have installed

查看:61
本文介绍了为什么我的 venv 使用的 pip 版本与我安装的版本不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置虚拟环境.我收到了关于过时 pip (19.2) 的警告,所以我在我的 (macos) 系统上全局更新了 pip,sudo -H python3 -m pip install --upgrade pip.它似乎有效,但是当我创建一个新的 venv 时,我仍然得到旧的 pip 版本.

% pip --version来自/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8) 的 pip 20.1% python3 -m pip --version来自/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8) 的 pip 20.1% rm -rf .venv # 确保% python3 -m venv .venv% ..venv/bin/激活(.venv) % python3 -m pip --version来自/Users/marvin/.venv/lib/python3.8/site-packages/pip (python 3.8) 的 pip 19.2.3(.venv) % pip --version来自/Users/marvin/.venv/lib/python3.8/site-packages/pip (python 3.8) 的 pip 19.2.3

旧版本来自哪里?

解决方案

Pip 会在任何新创建的 venv 中重新安装.venv 的默认 pip 版本与 Python 版本相关联,并且完全独立于您可能在系统上安装的任何 pip 版本.旧版本来自与 stdlib wheel 文件.org/3/library/ensurepip.html#module-ensurepip" rel="nofollow noreferrer">ensurepip 模块.这允许用户即使没有可用的互联网连接也可以创建 venv,如 venv 文档 提及:

<块引用>

除非给出了 --without-pip 选项,否则将调用 ensurepip 来引导 pip 进入虚拟环境

您可以使用 ensurepip 检查捆绑的 pip 版本.版本:

<预><代码>>>>导入确保pip>>>确保pip.version()'19.2.3'

Python 3.8.2 是 供应商 pip 19.2.3 和setuptools 41.2.0,与您所见相符.

要直接使用最新的 pip 版本创建 venvs,而不是使用旧的 pip 创建它们然后升级 pip 版本,请参阅此答案:

如何获取python -m venv"以直接安装最新的 pip 版本强>

I'm setting up virtual env. I was getting warnings about an outdated pip (19.2) so I updated pip on my (macos) system globally, sudo -H python3 -m pip install --upgrade pip. It seems to have worked, but when I make a new venv, I'm still getting the old pip version.

% pip --version           
pip 20.1 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
% python3 -m pip --version
pip 20.1 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
% rm -rf .venv # make sure
% python3 -m venv .venv   
% . .venv/bin/activate    
(.venv)     % python3 -m pip --version
pip 19.2.3 from /Users/marvin/.venv/lib/python3.8/site-packages/pip (python 3.8)
(.venv)     % pip --version           
pip 19.2.3 from /Users/marvin/.venv/lib/python3.8/site-packages/pip (python 3.8)

Where is the older version coming from?

解决方案

Pip is installed anew in any freshly created venv. The venv's default pip version is associated with the Python version, and is completely independent from whatever pip version you may have installed on the system. The older version comes from a wheel file bundled with the stdlib ensurepip module. This allows users to create a venv even with no internet connection available, as the venv docs mention:

Unless the --without-pip option is given, ensurepip will be invoked to bootstrap pip into the virtual environment

You can check the bundled pip version with ensurepip.version:

>>> import ensurepip
>>> ensurepip.version()
'19.2.3'

Python 3.8.2 is vendoring pip 19.2.3 and setuptools 41.2.0, matching what you've seen.

To create venvs directly with the latest pip version, rather than creating them with an older pip and then upgrading the pip version, refer to this answer:

How to get "python -m venv" to directly install latest pip version

这篇关于为什么我的 venv 使用的 pip 版本与我安装的版本不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆