Archive · Linux

Python 2 Reaches End of Life

Python 2 stopped being maintained on 1 January 2020. What that means for the scripts on your Linux servers.

1 min read

  • Ubuntu 18.04.3 LTS
  • Python 3.6
  • CentOS 8.1
  • Python 2.7

Python 2.7 was officially retired on 1 January 2020. The core team no longer fixes bugs or security issues, although distributions may still patch their own packages for a while.

Check what your servers use:

python --version          # may be missing, or Python 2.7
python3 --version         # Ubuntu 18.04 ships Python 3.6
grep -rl "^#!.*python$" /opt/scripts   # scripts still calling plain "python"

What to do:

  1. Change shebangs to #!/usr/bin/env python3.
  2. Run 2to3 or python-modernize on old scripts and read the diff.
  3. Pin dependencies in requirements.txt and test under Python 3.

CentOS 8 (current release 8.1) no longer installs a default python command at all; you choose with alternatives --set python /usr/bin/python3 or install a module. Ubuntu 18.04 keeps Python 2 available for compatibility, but treat it as legacy.