虚拟环境使用pip版本9创建,pip --version显示版本20

时间:2020-03-23 15:49:54

标签: python pip virtualenv

问题

我想创建一个虚拟环境($ python3 -m venv venv),每次看到pip list都给我20版本。

症状

创建虚拟环境时,我得到了过时的pip ...

╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ python3 -m venv venv

╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ source venv/bin/activate

(venv) ╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
pkg-resources (0.0.0)
setuptools (39.0.1)

所以,我调查了本地软件包

(venv) ╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ python3
>>> import os
>>> ... import site
>>> ... print(site.getsitepackages())
>>> ... os.listdir(site.getsitepackages()[0])
['/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.6/dist-packages']

然后我在本地文件系统中查看pip的内容


(venv) ╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ deactivate                                                                                                                                                                                                                                           127 ↵

╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ python3 -m pip install -U pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: pip in /home/mat/.local/lib/python3.6/site-packages (20.0.2)

╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ ll /usr/local/lib/python3.6/dist-packages | grep 'pip'

╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ ll /usr/lib/python3.6/dist-packages | grep 'pip'                                                                                                                                                                                                       1 ↵
ls: cannot access '/usr/lib/python3.6/dist-packages': No such file or directory

╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ ll  /usr/lib/python3/dist-packages | grep 'pip'                                                                                                                                                                                                        1 ↵
drwxr-xr-x 11 root root 4.0K Mar  5 14:07 pip
drwxr-xr-x  2 root root 4.0K Mar  5 14:07 pip-9.0.1.egg-info

现在我检查pip的版本

╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ pip --version
pip 20.0.2 from /home/mat/.local/lib/python3.6/site-packages/pip (python 3.6)

╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ pip3 --version
pip 20.0.2 from /home/mat/.local/lib/python3.6/site-packages/pip (python 3.6)

╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ ll /home/mat/.local/lib/python3.6/site-packages/pip
total 20K
-rw-r--r--  1 mat mat  455 Mar 14 11:30 __init__.py
drwxr-xr-x 13 mat mat 4.0K Mar 14 11:30 _internal
-rw-r--r--  1 mat mat  632 Mar 14 11:30 __main__.py
drwxr-xr-x  2 mat mat 4.0K Mar 14 11:30 __pycache__
drwxr-xr-x 19 mat mat 4.0K Mar 14 11:30 _vendor

因此,您可以看到python3 -m venv venv看上去/usr/lib/python3/dist-packages,而pip3 --version看上去/home/mat/.local/lib/python3.6/site-packages/pip

问题#1

如何配置 python3 ,这样当我输入python3 -m venv venv然后激活虚拟环境时,我可以输入pip list并看到版本20,就像我离开虚拟环境?

问题2

我认为因为输入pip --version并显示版本20,所以在创建虚拟环境时它也应该具有版本20。为什么不是这样?

问题3

以下输出显示pip版本9:

╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ ll  /usr/lib/python3/dist-packages | grep 'pip'                                                                                                                                                                                                        1 ↵
drwxr-xr-x 11 root root 4.0K Mar  5 14:07 pip
drwxr-xr-x  2 root root 4.0K Mar  5 14:07 pip-9.0.1.egg-info

那么,为什么下面的命令没有将/usr/lib/python3/dist-packages更改为版本20?

╭─mat@superelectron ~/code/mist-alpha ‹cassandra-api*› 
╰─$ python3 -m pip install -U pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: pip in /home/mat/.local/lib/python3.6/site-packages (20.0.2)

0 个答案:

没有答案