I've been using Ubuntu 20.04 for a few months now and things are going well, however recently I ran into 2 legacy applications which I'll need to start supporting that will require Python 2. As best as I can figure, I have at least the following choices:
- Go back to Ubuntu 18.04.5
- Install Python 2 in Ubuntu 20.04
- Attempt to install Python 2 in Ubuntu 20.04 but only in a virtual environment
- Use a VM
I'd prefer to stay away from the VM option b/c I use GPUs frequently which won't go through a VM and also b/c I do a lot of hardware/software interfacing for which using a VM may cause various problems. Also I don't like VMs generally (crashes, mouse/keyboard/screen hiccups, slow performance, etc.)
I'll be honest and admit I don't use virtual environments much, however I can say I'm not inclined towards this option as the 2 legacy applications I'm going to be supporting call Python various places (calling files that start new processes, etc.) that I suspect a virtual environment won't be able to handle. Also, I'v read about problems with an entire separate version of Python in a virtual environment, ex How to create python2.7 virtualenv on Ubuntu 20.04.
Ubuntu 18.04.5 was great but I'd prefer not to backdate at this point, which leaves me to consider installing Python 2. Upon a quick Googling I found many sites that explain the steps to install Python 2 in Ubuntu 20.04 (ex https://linuxconfig.org/install-python-2-on-ubuntu-20-04-focal-fossa-linux or https://www.vultr.com/docs/how-to-install-python-2-on-ubuntu-20-04), and most of these even include instructions on how to use update-alternatives
to make python
default to Python 2, which is a necessity in my case for supporting one of the legacy options I mentioned earlier.
I find it odd that something as major as installing an entire other version of Python does not cause problems with Ubuntu, since many Linux utilities today use Python. On the other hand Python 2 is offered as an official package by Canonical https://packages.ubuntu.com/focal/python2 and they are generally very good about package integration.
At this time here are my questions:
Can anybody that has installed Python 2 in Ubuntu 20.04 clarify if this caused problems? Are there any common applications that won't work after installing Python 2? Any other "gotchas" I should know about or look out for pertaining to this?
If I continue with the instructions above (
update-alternatives
to makepython
default to Python 2) will that potentially cause problems? Any "gotchas" pertaining to this additional step in particular?Has anybody tried a Python 2 virtual environment configuration (without a Python 2 native install) in Ubuntu? Is it really as easy as this page https://computingforgeeks.com/how-to-install-python2-with-virtualenv-on-ubuntu/ makes it sound? Will virtual environments work for supporting significant applications that call other scripts, use
python
(expecting it to be Python 2), span/fork other processes, etc?If the native Python 2 install on Ubuntu 20.04 and/or the virtual environment options are problematic, are there any other good options I haven't covered here?
You can do this, but there may be issues with Python 2 in the near future - pay attention to my later sections of this post!
Installing
python2
by default SHOULD makepython
be equivalent to Python 2 - if it doesn't then...There's already packages for this -
python-is-python2
is the one you'll want. Install that once you install Python 2. That'll handle the linking forpython
topython2.7
.I don't use plain virtualenv to get Python installs that differ from the system Python. I use PyEnv for this, because it makes individual userspace installations of Python. You will need the build dependencies for the
python
andpython2.7
installed -sudo apt build-dep python python2.7
should do it.Neither the native install nor the PyEnv approach will break anything. But there's quite a few things you need to be aware of.
Essentially... Python 2 Is Dead - both Upstream and in PyPA PIP (the
pip install ...
program)(NOTE: Some distributions may provide limited support for Python 2, but everything that is still reliant on Python 2 and NOT being migrated to Python 3 should be frowned upon)
Python PIP is not going to be supporting Python 2 as of four days ago with the 21.0 release of the underlying
pip
module. If you follow the PyEnv or individual separate Python 2 installation separate from System Python andpython-pip
's install, you will not be able to get Python modules for Python 2 anymore.Given that you're handling a legacy Python 2 program, I would strongly recommend you work on rewriting the program for Python 3. You are going to run into a TON of issues going forward if you have to maintain this legacy program beyond a year or two since the EOL date of 2020 - support for Python 2 is phased out upstream, and with PIP no longer supporting Python 2 you're going to start running into a ton of problems going forward keeping Python 2 applications around.
For most programs it's not supremely hard to port Python 2 programs to Python 3. If your dependent libraries (and NOT the underlying Python 2 code itself) are only Python 2 then you're going to run into long term support problems - and you REALLY should be looking to replace / upgrade the process.