如何获得“python -m venv"直接安装最新的pip版本 [英] How to get "python -m venv" to directly install latest pip version
问题描述
作为新 Python 版本编译步骤的一部分,我获取并运行 get-pip.py
,在python可执行文件旁边安装最新的pip:
$/opt/python/3.7.0/bin/python --version蟒蛇 3.7.0$/opt/python/3.7.0/bin/pip --version来自/opt/python/3.7.0/lib/python3.7/site-packages/pip (python 3.7) 的 pip 18.0
我在 /opt/python
下有 25 个这样的版本,虽然我主要使用每个 Major.minor 版本的五个最新版本,但不是 EOL.为了设置一个环境,我曾经使用 -p/opt/python/XYZ/bin/python
选项运行 virtualenv
或我的 virtualenvutils
以获得具有特定版本的虚拟环境.
在 Python 3.7 中,这会给出 imp 模块弃用警告:
$ virtualenv -p/opt/python/3.7.0/bin/python/tmp/py37virtualenv使用解释器运行 virtualenv/opt/python/3.7.0/bin/python使用基本前缀'/opt/python/3.7.0'/opt/util/virtualenvutils/lib/python3.6/site-packages/virtualenv.py:1041: DeprecationWarning: 不推荐使用imp 模块而支持importlib;有关其他用途,请参阅模块的文档进口进口/tmp/py37virtualenv/bin/python 中的新 python 可执行文件安装 setuptools、pip、wheel...完成.
我不太希望这会在 virtualenv 中得到解决,因为至少从 2014 年开始就有一个 PendingDeprecationWarning
(从 这个问题)
在研究将 virtualenv
替换为 virtualenvutils
中的 python -m venv
时,我首先创建了一个新的基于 venv
手动虚拟环境:
$/opt/python/3.7.0/bin/python -m venv/tmp/py37venv$/tmp/py37venv/bin/pip --version来自/tmp/py37venv/lib/python3.7/site-packages/pip (python 3.7) 的 pip 10.0.1
那有一个旧的 pip
版本!如果你使用它,你会得到:
您使用的是 pip 版本 10.0.1,但是版本 18.0 可用.
您应该考虑通过pip install --upgrade pip"命令进行升级
在使用 virtualenv
创建的虚拟环境中,您会立即获得最新版本:
$/tmp/py37virtualenv/bin/pip --version来自/tmp/py37virtualenv/lib/python3.7/site-packages/pip (python 3.7) 的 pip 18.0
我可以运行创建后步骤:
/tmp/py37venv/bin/pip install -U --disable-pip-version-check pip
这需要额外的时间.如果 pip
有一些安全更新,这意味着运行非安全版本以获得安全版本,这是一个理想的攻击点.
从 virtualenvutils
执行多个步骤来创建一个 pip
-less virtualenv 然后使用 get 添加
.从命令行这不是那么简单:pip
是微不足道的-pip.py
$/opt/python/3.7.0/bin/python -m venv --without-pip/tmp/py37venvnopip$/tmp/py37venvnopip/bin/python -c "from urllib.request import urlopen; response = urlopen('https://bootstrap.pypa.io/get-pip'); open('/tmp/tmp_get_pip.py', 'w').write(response.read())"$/opt/python/3.7.0/bin/python/tmp/tmp_get_pip.py......$/opt/python/3.7.0/bin/pip --version
来自/opt/python/3.7.0/lib/python3.7/site-packages/pip (python 3.7) 的 pip 18.0
是什么导致 /opt/python/3.7.0/bin/python -m venv
采用旧的 pip
版本?3.7.0 发布的时候有那个版本吗?
如何以某种方式更新 /opt/python/3.7.0
下的安装,以便使用 /opt/python/3.7.0/bin/python -m venv
使用最新的 pip
版本创建一个 virtualenv,而无需恢复到脚本、别名或使用多个命令?将最新的 pip
安装在 /opt/python/3.7.0
下显然是不够的.
有两个捆绑的轮子:
/opt/python/3.7.0/lib/python3.7/ensurepip/_bundled/setuptools-39.0.1-py2.py3-none-any.whl/opt/python/3.7.0/lib/python3.7/ensurepip/_bundled/pip-10.0.1-py2.py3-none-any.whl
我怀疑我需要更新这些.有没有比手动更新更好的方法?/some/python -m venv
的一些选项会很好.
(并且运行 /some/python -m ensurepip --upgrade
不起作用)
运行已弃用的 /opt/python/3.7.0/bin/pyvenv
具有相同的旧 pip
版本问题.
我使用 upgrade-ensurepip
来更新那些 pip
和 setuptools
轮ensurepip
包中的文件.它不像能够通过 pip
升级 ensurepip
那样优雅,但它仍然比手动升级更可取.
https://pypi.org/project/upgrade-ensurepip/>
As part of the compilation step for a new python version, I fetch and run get-pip.py
, to have the latest pip installed next to the python executable:
$ /opt/python/3.7.0/bin/python --version
Python 3.7.0
$ /opt/python/3.7.0/bin/pip --version
pip 18.0 from /opt/python/3.7.0/lib/python3.7/site-packages/pip (python 3.7)
I have 25 such versions under /opt/python
, although I mostly use the five latest versions of each major.minor version that is not EOL. To setup an invironment I used to run virtualenv
or my virtualenvutils
with the -p /opt/python/X.Y.Z/bin/python
option to get a virtual environment with a specific version.
With Python 3.7 this gives the imp module deprecation warning:
$ virtualenv -p /opt/python/3.7.0/bin/python /tmp/py37virtualenv
Running virtualenv with interpreter /opt/python/3.7.0/bin/python
Using base prefix '/opt/python/3.7.0'
/opt/util/virtualenvutils/lib/python3.6/site-packages/virtualenv.py:1041: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
New python executable in /tmp/py37virtualenv/bin/python
Installing setuptools, pip, wheel...done.
I have little hope this will be solved in virtualenv, as this has had a PendingDeprecationWarning
at least since 2014 (as can be seen from the output in this question)
While investigating replacing virtualenv
with python -m venv
in virtualenvutils
, I first created a new venv
based virtual environment by hand:
$ /opt/python/3.7.0/bin/python -m venv /tmp/py37venv
$ /tmp/py37venv/bin/pip --version
pip 10.0.1 from /tmp/py37venv/lib/python3.7/site-packages/pip (python 3.7)
That has an old pip
version! If you use it, you'll get:
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command
In the virtual environment created with virtualenv
you immediately get the latest version:
$ /tmp/py37virtualenv/bin/pip --version
pip 18.0 from /tmp/py37virtualenv/lib/python3.7/site-packages/pip (python 3.7)
I can run a post-creation step:
/tmp/py37venv/bin/pip install -U --disable-pip-version-check pip
which will take extra time. And if there was a some security update for pip
, this would imply running the non-secure version to get a secure version, an ideal point of attack.
From virtualenvutils
it is trivial to do the multiple steps to create a pip
-less virtualenv and then add pip
using get-pip.py
. From the command-line this is not so simple:
$ /opt/python/3.7.0/bin/python -m venv --without-pip /tmp/py37venvnopip
$ /tmp/py37venvnopip/bin/python -c "from urllib.request import urlopen; response = urlopen('https://bootstrap.pypa.io/get-pip'); open('/tmp/tmp_get_pip.py', 'w').write(response.read())"
$ /opt/python/3.7.0/bin/python /tmp/tmp_get_pip.py
......
$ /opt/python/3.7.0/bin/pip --version
pip 18.0 from /opt/python/3.7.0/lib/python3.7/site-packages/pip (python 3.7)
What is causing /opt/python/3.7.0/bin/python -m venv
to take that old pip
version? Is that the version available when 3.7.0 was released?
How can I update my install under /opt/python/3.7.0
in some way so that using /opt/python/3.7.0/bin/python -m venv
creates a virtualenv with the latest pip
version without reverting to scripts, aliases or using multiple commands? Having the latest pip
installed under /opt/python/3.7.0
obviously is not enough.
There are two bundled wheels:
/opt/python/3.7.0/lib/python3.7/ensurepip/_bundled/setuptools-39.0.1-py2.py3-none-any.whl
/opt/python/3.7.0/lib/python3.7/ensurepip/_bundled/pip-10.0.1-py2.py3-none-any.whl
I suspect I need to update those. Is there a better way than updating those by hand? Some option for /some/python -m venv
would be nice.
(And running /some/python -m ensurepip --upgrade
doesn't do the trick)
Running the deprecated /opt/python/3.7.0/bin/pyvenv
has the same old pip
version problem.
I use upgrade-ensurepip
to update those pip
and setuptools
wheel files that are part of the ensurepip
package. It's not as elegant as being able to upgrade ensurepip
via pip
, but it's still preferable to doing it manually.
https://pypi.org/project/upgrade-ensurepip/
这篇关于如何获得“python -m venv"直接安装最新的pip版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!