如何获取"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
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)
我在/opt/python
下有25个这样的版本,尽管我主要使用每个major.minor版本(不是EOL)的五个最新版本.要设置环境,我曾经使用-p /opt/python/X.Y.Z/bin/python
选项运行virtualenv
或virtualenvutils
以获取具有特定版本的虚拟环境.
在Python 3.7中,这会给出imp模块弃用的警告:
$ 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.
我几乎不希望在virtualenv中解决此问题,因为至少从2014年起它已经出现 在使用 我可以执行创建后的步骤: 这将花费额外的时间.而且,如果 在 来自/opt/python/3.7.0/lib/python3.7/site-packages/pip(python 3.7)的pip 18.0 是什么原因导致 如何以某种方式更新 有两个捆绑的轮子: 我怀疑我需要更新这些内容.有没有比手动更新更好的方法? (运行 运行已弃用的 我使用 https://pypi.org/project/upgrade-ensurepip/ > As part of the compilation step for a new python version, I fetch and run I have 25 such versions under With Python 3.7 this gives the imp module deprecation warning: I have little hope this will be solved in virtualenv, as this has had a While investigating replacing That has an old You are using pip version 10.0.1, however version 18.0 is available. In the virtual environment created with I can run a post-creation step: which will take extra time. And if there was a some security update for From pip 18.0 from /opt/python/3.7.0/lib/python3.7/site-packages/pip (python 3.7) What is causing How can I update my install under There are two bundled wheels: I suspect I need to update those. Is there a better way than updating those by hand? Some option for (And running Running the deprecated I use https://pypi.org/project/upgrade-ensurepip/ 这篇关于如何获取"python -m venv"直接安装最新的pip版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!PendingDeprecationWarning
(从
virtualenv
创建的虚拟环境中,您会立即获得最新版本:$ /tmp/py37virtualenv/bin/pip --version
pip 18.0 from /tmp/py37virtualenv/lib/python3.7/site-packages/pip (python 3.7)
/tmp/py37venv/bin/pip install -U --disable-pip-version-check pip
pip
有一些安全更新,这将意味着运行非安全版本以获得安全版本,这是理想的攻击点.virtualenvutils
中,很容易执行多个步骤来创建较少pip
的virtualenv,然后使用get-pip.py
添加pip
.从命令行开始,这不是那么简单:$ /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/bin/python -m venv
采用旧的pip
版本?该版本在3.7.0发行时可用吗? /opt/python/3.7.0
下的安装,以便使用/opt/python/3.7.0/bin/python -m venv
创建具有最新pip
版本的virtualenv,而无需恢复脚本,别名或使用多个命令?在/opt/python/3.7.0
下安装最新的pip
显然是不够的./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
更新了ensurepip
软件包中的pip
和setuptools
滚轮文件.它不像可以通过pip
升级ensurepip
那样优雅,但还是比手动完成更可取.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)
/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.$ 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.
PendingDeprecationWarning
at least since 2014 (as can be seen from the output in this question)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)
pip
version! If you use it, you'll get:
You should consider upgrading via the 'pip install --upgrade pip' commandvirtualenv
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)
/tmp/py37venv/bin/pip install -U --disable-pip-version-check pip
pip
, this would imply running the non-secure version to get a secure version, an ideal point of attack.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
/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? /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./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
would be nice./some/python -m ensurepip --upgrade
doesn't do the trick)
/opt/python/3.7.0/bin/pyvenv
has the same old pip
version problem. 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.