Python venv pip is always outdated.

huangapple go评论50阅读模式
英文:

Python venv pip is always outdated

问题

以下是您要翻译的内容:

"Whenever I create a fresh Python 3.11 virtual environment using venv, the provided pip always prompts me to update to the latest version, even though my base version appears to be up to date

$ python3.11 -m pip --version
pip 23.0.1 from /opt/homebrew/lib/python3.11/site-packages/pip (python 3.11)
$ python3.11 -m venv venv
$ source venv/bin/activate.fish
(venv) $ pip install requests
...
Successfully installed ...

[notice] A new release of pip available: 22.3.1 -> 23.0.1
[notice] To update, run: pip install --upgrade pip

Why doesn't the virtual environment have the newest release to begin with? Is there a way I can manually set it for future virtual environments? I'd like to not have to deal with this slight inconvenience every time I create a new virtual environment."

英文:

Whenever I create a fresh Python 3.11 virtual environment using venv, the provided pip always prompts me to update to the latest version, even though my base version appears to be up to date

$ python3.11 -m pip --version
pip 23.0.1 from /opt/homebrew/lib/python3.11/site-packages/pip (python 3.11)
$ python3.11 -m venv venv
$ source venv/bin/activate.fish
(venv) $ pip install requests
...
Successfully installed ...

[notice] A new release of pip available: 22.3.1 -> 23.0.1
[notice] To update, run: pip install --upgrade pip

Why doesn't the virtual environment have the newest release to begin with? Is there a way I can manually set it for future virtual environments? I'd like to not have to deal with this slight inconvenience everytime I create a new virtual environment.

答案1

得分: 3

The venv module uses the ensurepip module to install a hard-coded version of pip that is bundled with ensurepip itself. While pip is not part of the standard library, ensurepip is. It does this, I believe, for a couple of reasons:

  1. You know exactly what version of pip will initially be installed for a given version of Python, no matter what machine you are using.
  2. You can create a virtual environment without needing a network connection to download pip from PyPI or elsewhere.

You can see the wheel used to install pip by looking in the directory containing the ensurepip package.

Code snippet translated:

>>> import pathlib, ensurepip
>>> list(pathlib.Path(ensurepip.__file__).parent.glob('*/pip*'))
[PosixPath('[...]/python3.9/ensurepip/_bundled/pip-21.3.1-py3-none-any.whl')]
英文:

The venv module uses the ensurepip module to install a hard-coded version of pip that is bundled with ensurepip itself. While pip is not part of the standard library, ensurepip is. It does this, I believe, for a couple of reasons:

  1. You know exactly what version of pip will initially be installed fora given version of Python, no matter what machine you are using.
  2. You can create a virtual environment without needing a network connection to download pip from PyPI or elsewhere.

You can see the wheel used to install pip by looking in the directory containing the ensurepip package.

>>> import pathlib, ensurepip
>>> list(pathlib.Path(ensurepip.__file__).parent.glob('*/pip*'))
[PosixPath('[...]/python3.9/ensurepip/_bundled/pip-21.3.1-py3-none-any.whl')]

huangapple
  • 本文由 发表于 2023年3月4日 02:44:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75630794.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定