Python 2包和Python 2解释器版本的差异
我不太明白在我的Ubuntu 16.04系统上各种Python 2软件包和Python 2解释器之间版本的明显不同意见。
运行
$ readlink -e $(which python python2) /usr/bin/python2.7 /usr/bin/python2.7 $ python --version && python2 --version Python 2.7.12 Python 2.7.12
告诉我python
和python2
链接到python2.7
,我系统上的Python 2解释器的版本是Python 2.7.12
。 到目前为止这么好,没什么可惊讶的。
运行
$ dpkg -s python | grep Version Version: 2.7.11-1
告诉我python
包的版本是2.7.11-1
,它不同意Python 2解释器的版本。
另一方面,跑步
$ dpkg -s python2.7 | grep Version Version: 2.7.12-1~16.04
告诉我python2.7
包的版本是2.7.12
,它与Python 2解释器的版本一致。
鉴于Python 2解释器的版本是2.7.12
,那么解释器是否仅由python2.7
包提供? 如果是这样,如果python
包不提供系统当前使用的解释器,它会做什么?
解释器/usr/bin/python2.7
由python2.7-minimal
包提供,正如您可以在apt-file search /usr/bin/python2.7
看到的那样。 python
包就是所谓的元数据包 :因为Python安装是在几个包之间拆分的,所以python
包提供了一种简单的方法来一次安装所有这些包。 如果有人只需要最低限度,他们只能安装python2.7-minimal
软件包。
默认情况下,您安装了许多版本的Python。 如果程序需要特定版本,则作者将通过路径名调用该版本。
如果您没有作者所需的版本,则可以安装该特定版本。 您仍然可以维护/usr/bin/python
符号链接到版本号的默认版本选项。 在您的情况下,它很可能链接到/usr/bin/python2.7
。
您可以使用以下方式查看已安装的版
$ ls -ld /usr/bin/python*
我的回答主要是解决你问题的最后一部分, If so, what does the python package do if it doesn't provide the interpreter that the system currently uses?
, If so, what does the python package do if it doesn't provide the interpreter that the system currently uses?
。
当你运行python
它正在搜索你的路径并找到/usr/bin/python
,它链接到/usr/bin/python
。 所以你实际上是在检查/usr/bin/python2.7
的版本。
此外,根据检查的方法,有时版本输出会有差异 。 在这种情况下,通过实际程序检查并通过分发包装进行检查。 发生这种情况时,实际程序中的版本标记最有可能更精确。
另一种validationpython解释器实际版本的方法是从命令行运行它:
$ python
输出:
Python 2.7.12 (default, Jul 1 2016, 15:12:24) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> $ python2.7
输出:
Python 2.7.12 (default, Jul 1 2016, 15:12:24) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>