Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

python - Why is my venv using a different pip version than I have installed

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 is currently 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...