为什么"python3 -m venv myenv"将比我在系统上任何位置都能找到的任何版本的pip都更旧的pip版本安装到myenv中? [英] Why 'python3 -m venv myenv' installs older version of pip into myenv than any version of pip I can find anywhere on the system?
问题描述
这不会引起我通过激活虚拟环境并运行pip install -U pip
无法解决的任何问题,但是我总是想知道旧版本的pip来自何处.
我正在使用OS X 10.7.5.当我使用pyvenv-3.4 myenv
或python3 -m venv myenv
创建虚拟环境时,虚拟环境中安装的pip版本是6.0.8,但是我已将全局pip升级到6.1.1.
这是一次终端会议,展示了我的意思:
$ python3 -m venv myenv
$ myenv/bin/pip -V
pip 6.0.8 from /Users/dust/Desktop/myenv/lib/python3.4/site-packages (python 3.4)
这就是我想发生的事情:
$ source myenv/bin/activate
(myenv)$ pip -V
UPDATED SYSTEM VERSION HERE WOULD BE NICE
除了在虚拟环境中创建的内容外,我在其他任何地方都找不到pip 6.0.8.
以下是我尝试用来解决此问题的各种命令的输出:
$ which pip
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip
$ which pip3
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip3
$ pip -V
pip 6.1.1 from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
$ pip3 -V
pip 6.1.1 from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
我什至尝试使用find:
$ find / -type f -name pip 2>&1 | awk '! /^f.*$/'
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip
/usr/local/bin/pip
$ find / -type f -name pip3 2>&1 | awk '! /^f.*$/'
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip3
我想也许/usr/local/bin/pip
可能是罪魁祸首,但没有:
$ /usr/local/bin/pip -V
pip 6.1.1 from /Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg (python 2.7)
嗯.也许OS X python有它?
$ /usr/bin/python
>>> import pip
>>> pip.__version__
'6.1.1'
不论我问的是哪个python发行版,都报告了
6.1.1,无论是OS X的2.7.1,python.org的2.7.9还是python.org的3.4.3.
是否有可能(或建议)更新放入虚拟环境中的pip版本?
我在运行OSX 10.10.2
和python 3.4.2
时遇到相同的问题.最近,我在使用python 3.4.3
的debian wheezy
机器中创建了虚拟环境,并最终使用了比可用版本更旧的pip
版本.必须升级pip
.
我一直在手动将虚拟环境中的pip
从6.0.8
升级到6.1.1
,因为我正以这种方式使用软件库版本-是的,我正在将python 3
版本升级到3.4.3
现在.无论如何,我系统的python3-pip
是最新版本6.1.1
,所以我也想知道为什么pyvenv
创建一个新的虚拟环境并使用旧的pip
加载它.
我没有注意到由于升级pip
而在任何虚拟环境中发生任何不良情况,(但另一方面,我也没有注意到任何良好的情况)显然,新点子更快-没做.不会引起注意,并且成功安装后输出的垃圾更少,这是因为用户不在乎-也没有注意到,可能是因为我是不在乎的人之一,并且还配备了最先进的咖啡能拿铁艺术启动的机器!!! -仍在等待sudo pip install latte
完成:(
因此,要回答您的问题,绝对有可能,并且建议升级,因为显然新的pip
修复了一些错误并且运行得更快,但是我想速度并不是那么重要,而且该错误修复不会影响很多人(使用旧版pip
我从未遇到过错误).
您可以在创建新的虚拟环境时使用标志--system-site-packages链接到系统站点软件包
pyvenv myenv --system-site-packages
这将链接到您系统级的pip,并消除了在每个虚拟环境上手动升级pip的烦恼,但是如果您这样做,那么您的虚拟环境是否就是虚拟的?
更新:按照上面的说明,我进入了venv
包的源进行挖掘. pip
是通过文件__init__.py
第248行
_setup_pip
的方法设置的
def _setup_pip(self, context):
"""Installs or upgrades pip in a virtual environment"""
# We run ensurepip in isolated mode to avoid side effects from
# environment vars, the current directory and anything else
# intended for the global Python environment
cmd = [context.env_exe, '-Im', 'ensurepip', '--upgrade',
'--default-pip']
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
因此,venv似乎正在使用subprocess
模块从外壳中调用ensurepip
.
再过一分钟的google-fu,从文档中的"ensurepip"文件中给了我.
ensurepip.version()
返回一个字符串,该字符串指定在引导环境时将要安装的pip捆绑版本.
因此,从命令行输入以下代码:
$ python3 -c 'import ensurepip; print(ensurepip.version())'
6.0.8
显示我当前的pip
,它将用ensurepip
引导.
我想在升级ensurepip
之前,每次安装新版本都必须使用pip
的旧版本,因为我找不到升级ensurepip
随附的pip版本的方法>
This is not causing me any problem that I can't solve by activating the virtual environment and running pip install -U pip
, but I always wonder where the older version of pip is coming from.
I'm using OS X 10.7.5. When I create a virtual environment using either pyvenv-3.4 myenv
or python3 -m venv myenv
, the version of pip that is installed inside the virtual environment is 6.0.8, but I have upgraded my global pip to 6.1.1.
Here is a terminal session demonstrating what I mean:
$ python3 -m venv myenv
$ myenv/bin/pip -V
pip 6.0.8 from /Users/dust/Desktop/myenv/lib/python3.4/site-packages (python 3.4)
Here is what I would like to occur:
$ source myenv/bin/activate
(myenv)$ pip -V
UPDATED SYSTEM VERSION HERE WOULD BE NICE
I can't find a pip 6.0.8 anywhere else, other than what is created inside virtual environments.
Here are the outputs of various commands that I have use to try and figure this out:
$ which pip
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip
$ which pip3
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip3
$ pip -V
pip 6.1.1 from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
$ pip3 -V
pip 6.1.1 from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
I even tried using find:
$ find / -type f -name pip 2>&1 | awk '! /^f.*$/'
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip
/usr/local/bin/pip
$ find / -type f -name pip3 2>&1 | awk '! /^f.*$/'
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip3
I thought maybe that the /usr/local/bin/pip
might have been the culprit, but no:
$ /usr/local/bin/pip -V
pip 6.1.1 from /Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg (python 2.7)
Hmm. Perhaps the OS X python has it?
$ /usr/bin/python
>>> import pip
>>> pip.__version__
'6.1.1'
6.1.1 is reported no matter which distribution of python I ask, whether it be OS X's 2.7.1, python.org's 2.7.9, or python.org's 3.4.3.
Is it possible (or advisable) to update the version of pip that gets put into a virtual environment?
I face the same issue, running OSX 10.10.2
and python 3.4.2
. Most recently I created a virtual environment in a debian wheezy
machine with python 3.4.3
and also ended up with an older version of pip
than available. had to upgrade pip
.
I've been upgrading pip
within the virtual environment to 6.1.1
from 6.0.8
manually, because I'm o.c.d about software library versions that way - and yes, I am upgrading my python 3
version to 3.4.3
right now. Anyway, my system's python3-pip
is the latest version 6.1.1
, so I've also wondered why pyvenv
creates a new virtual environment and loads it with old pip
.
I haven't noticed anything bad happen in any of the virtual environments due to upgrading pip
, (but on the flip side, I haven't noticed anything good either) Apparently the new pip is faster -- didn't notice, and outputs less junk on successful installs because user's don't care -- also didn't notice, probably because i'm one of those that don't care, and also comes with a state-of-the art coffee machine capable of latte art to boot!!! -- still waiting on sudo pip install latte
to finish :(
So, to answer your question, it is definitely possible, and probably advisable to upgrade, because apparently the new pip
fixes some bugs and goes faster, but I guess the speed up isn't that major, and the bug fixes don't affect all that many people (I've never faced a bug with my usage of the old pip
).
You can link to system site-packages using the flag --system-site-packages when you create a new virtual environment, like this
pyvenv myenv --system-site-packages
This will link to your system wide version of pip, and would remove the annoyance that is manually upgrading pip on every virtual environment, but if you do this, then is your virtual environment all that virtual?
update: following my rant above, I went into the venv
package's source to dig. pip
is set up by a method called _setup_pip
in the file __init__.py
, line 248
def _setup_pip(self, context):
"""Installs or upgrades pip in a virtual environment"""
# We run ensurepip in isolated mode to avoid side effects from
# environment vars, the current directory and anything else
# intended for the global Python environment
cmd = [context.env_exe, '-Im', 'ensurepip', '--upgrade',
'--default-pip']
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
So, venv seems to be calling ensurepip
from the shell using the subprocess
module.
One more minute of google-fu gave me this from the documentation for ensurepip.
ensurepip.version()
Returns a string specifying the bundled version of pip that will be installed when bootstrapping an environment.
So, from the command line, the following code:
$ python3 -c 'import ensurepip; print(ensurepip.version())'
6.0.8
displays my current pip
that will be bootstrapped with ensurepip
.
I guess we're stuck with the old version of pip
for every new install until ensurepip
gets upgraded, as I can't find a way to upgrade the version of pip that comes with ensurepip
这篇关于为什么"python3 -m venv myenv"将比我在系统上任何位置都能找到的任何版本的pip都更旧的pip版本安装到myenv中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!