3

I don't quite understand the apparent disagreement in versions between the various Python 2 packages and the Python 2 interpreter on my Ubuntu 16.04 system.

Running

$ 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

tells me that python and python2 are symlinked to python2.7 and the version of the Python 2 interpreter on my system is Python 2.7.12. So far so good, nothing surprising.

Running

$ dpkg -s python | grep Version
Version: 2.7.11-1

tells me that the version of the python package is 2.7.11-1, which disagrees with the version of the Python 2 interpreter.

On the other hand, running

$ dpkg -s python2.7 | grep Version
Version: 2.7.12-1~16.04

tells me that the version of the python2.7 package is 2.7.12, which agrees with the version of the Python 2 interpreter.

Given that the version of the Python 2 interpreter is 2.7.12, is the interpreter then provided by only the python2.7 package? If so, what does the python package do if it doesn't provide the interpreter that the system currently uses?

1
  • Both the python and python2.7 packages in the official 16.04 repositories are at version 2.7.11-1. Do you have third-party repositories enabled? – fkraiem Sep 17 '16 at 12:49
4

The interpreter /usr/bin/python2.7 is provided by the python2.7-minimal package, as you can see with apt-file search /usr/bin/python2.7. The python package is what is called a metapackage: because the Python installation is split between several packages, the python package provides a simple way to install all those packages at once. If someone needs only the bare minimum, they can install only the python2.7-minimal package.

1

By default you have a number of versions of Python installed. If a program required a specific version, the author would call on that version by the path-name.

If you don't have the author's required version you could install that specific version. You can still maintain your default version choice which /usr/bin/python symbolic linked to the the version number. In your case, it's most likely linked to /usr/bin/python2.7.

You can view your installed versions with:

$ ls -ld /usr/bin/python*

My answer is mostly addressing the last part of your question, If so, what does the python package do if it doesn't provide the interpreter that the system currently uses?.

When you run python it's searching your path and finding /usr/bin/python, which is linked to /usr/bin/python. So you're actually checking the version of /usr/bin/python2.7.

Also, on occasions there are discrepancies in the version output depending on the method checked. As in this case, checking via the actual program and checking via the distribution packaging. When this occurs the version stamp in the actual program would be the most likely be more precise.

Another way to verify the actual version of the python interpreter is by running it from the commandline:

$ python

Output:

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

Output:

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.
>>>
2
  • @Zanna I mean packages installed by the user from the repository from using sudo apt. It unlikely that a developer would would look for an installed Python in /uer/local or anywhere else beside /usr/bin. – L. D. James Sep 17 '16 at 10:17
  • @Zanna I just happened to be reading a year old post. It's incredible how a person so often sees what they are expecting rather than what's there. I'm just noticing my typo /usr/local/bin/python* and understand your comment differently. I'm upvoting your comment and fixing my answer. Thanks! By the way, let me know if you see other discrepancies. I'll try to be more thorough in the future. – L. D. James Sep 14 '17 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.