Why does "python3 -m venv myenv" install an older version of pip in myenv than any pip version that I can find anywhere on the system?

This does not cause me any problems that I cannot solve by activating the virtual environment and running pip install -U pip , but I always wonder where the older version of pip comes from.

I am using OS X 10.7.5. When I create a virtual environment using pyvenv-3.4 myenv or python3 -m venv myenv , the pip version installed inside the virtual environment is 6.0.8, but I updated 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 do:

 $ source myenv/bin/activate (myenv)$ pip -V UPDATED SYSTEM VERSION HERE WOULD BE NICE 

I can not find pip 6.0.8 anywhere else besides what is created in virtual environments.

Here are the outputs of the various commands that I use to try to 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 it might be that /usr/local/bin/pip might be 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) 

Hm. Maybe it has python OS X?

 $ /usr/bin/python >>> import pip >>> pip.__version__ '6.1.1' 

6.1.1 is reported no matter what python distribution I specify, be it OS X 2.7.1, python.org 2.7.9, or python.org 3.4.3.

Is it possible (or desirable) to upgrade the version of pip that gets into the virtual environment?

+6
source share
1 answer

I am facing the same problem running OSX 10.10.2 and python 3.4.2 . Most recently, I created a virtual environment on a debian wheezy machine with python 3.4.3 , and also got an older version of pip than is available. had to update pip .

I updated pip in a virtual environment to 6.1.1 from 6.0.8 manually, because I paid for it in software library versions - and yes, I am upgrading python 3 to 3.4.3 right now. Anyway, my python3-pip is the latest version 6.1.1 , so I also wondered why pyvenv creates a new virtual environment and loads it using the old pip .

I did not notice anything bad in any virtual environment due to the pip update (but, on the other hand, I also did not notice anything). Obviously, the new pip is faster - t notifies and displays less garbage on successful installations because the user does not care - also did not notice, probably because I am one of those who do not care, and also comes with the most modern coffee machine, capable of latte art for download !!! - still waiting for completion sudo pip install latte : (

So, in order to answer your question, this is definitely possible and probably advisable to update, because, apparently, the new pip fixes some errors and goes faster, but I think that acceleration is not so important, and the correction error is not affect everything that many people (I never encountered an error using the old pip ).

You can refer to system package sites using flag -system-site packages when creating a new virtual environment, for example

 pyvenv myenv --system-site-packages 

This will link to your pip system version and eliminate the annoyance that manually updates pip in each virtual environment, but if you do, will your virtual environment be virtual?

update: after my rant above, I went to the venv package venv to dig. pip configured by the _setup_pip method in the __init__.py file, 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 invoke ensurepip from the shell using the subprocess module.

Another google-fu minute gave me this from the documentation for provision .

ensurepip.version ()

Returns a string indicating the nested version of the pip that will be installed when the environment boots.

So, from the command line, the following code:

 $ python3 -c 'import ensurepip; print(ensurepip.version())' 6.0.8 

displays the current current pip to be loaded using ensurepip .

I think we are stuck with the old version of pip for each new installation until ensurepip is updated, since I cannot find a way to upgrade the version of pip that comes with ensurepip

+3
source

Source: https://habr.com/ru/post/985318/


All Articles