1

which python shows nothing. The following command fixes the issue

/usr/bin$ sudo ln -s python3 python

But is it a common, safe solution?

which python
/usr/bin/python
  • 1
    As I remember /usr/bin/python should be linked to python2 and not 3! And use update-alternatives to fix these kind of links. I guess installing/reinstalling python-minimal should fix the issue. – Ravexina Jul 12 at 17:55
5

No, that's not safe or common at all.

  • Historically python refers to python2, not python3
  • Many python(2) scripts will break if run using the py3 interpreter
  • The reverse is also true: Many py3 scripts will break if run using the py2 interpreter.
  • There is no graceful failure - a script run using the wrong interpreter simply spits out a series of cryptic error and quits.

See PEP 394 for all the details on what the 'python' command should symlink to. Don't stop at the 8-year-old first paragraph, read the entire history section to see how the recommendations have changed over time.

Older releases of Ubuntu (16.04 and older) include both Python2 and Python3 with the default install. Changing python on these releases may break your system quite terribly.

Newer releases of Ubuntu (18.04 and newer) include only Python3 with the default install. However, Python2 is trivial to install (sudo apt install python2).

Python2 will reach End of Life during 2020, according to PEP 373. However, changing python afterward is still not recommended at present.

  • Ok, but what is solution of the problem? – mrgloom Jul 13 at 15:43
  • 2
    If, in a newly-installed release of Ubuntu 18.04 or newer, the command which python returns nothing...that's not a problem. That's an expected behavior. It's supposed to return nothing when Python 2 is not installed. – user535733 Jul 14 at 1:18

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.