Running a Python2 program with Python3?
EDIT: Updates below, the scenery seems to have changed significantly.
I have Ubuntu 20.04, and have installed Python 3.10 manually. There's python 2 in the system already, and that's what I get if I simply execute python
at a command line, rather than python3
. However, I only seem to have a version of pip that is specific to python3.
I have a program that I want to run (chirp) which is written in python2. It complains of the lack of a serial library:
$ ./chirpw
Traceback (most recent call last):
File "./chirpw", line 24, in <module>
from chirp.drivers import *
File "/home/simon/chirp-daily-20220103/chirp/drivers/idrp.py", line 16, in <module>
import serial
ImportError: No module named serial
However, if I attempt to get this module with pip, I end up with pip3 running and get the python3 version of this module.
How should I go about adding a library to python2 specifically (and ensure that the library that's fetched is the python2 library)?
I suppose the "best" way might be to create a virtual environment specifically for this particular program, but I don't know how to do that in the case of a pre-existing program either.
Any pointers gratefully accepted.
EDIT. I found this page: setting up pipenv and virtualenvironments and I seem to have moved forward. I now seem to have an actual virtual environment built around /usr/bin/python (which is python2.7), and using it, pip -install serial worked. However, after doing this, it's now complaining that it can't find the module gtk, and the attempt to load that module fails saying there's no such module:
(venv) :~/chirp-daily-20220103$ python -m pip install gtk
DEPRECATION:[...]
ERROR: Could not find a version that satisfies the requirement gtk (from versions: none)
ERROR: No matching distribution found for gtk
Next I tried the flatpak version of this, but flatpak isn't working for me at all. I'll open a different question on that, since we're now well off my original question's topic.
Thanks to all who tried to help :)
As we already know CHIRP is also provided as Flatpak and this installation method is easier.
But if you still want to proceed with installation from source tar-ball - use below commands:
sudo apt-get update
sudo apt-get install python2 python2-dev python-is-python2
cd ~/Downloads
# three below command will download old packages from 18.04 LTS repository
wget -c http://archive.ubuntu.com/ubuntu/pool/main/p/pyserial/python-serial_3.4-2_all.deb
wget -c http://archive.ubuntu.com/ubuntu/pool/universe/p/pygtk/python-gtk2_2.24.0-5.1ubuntu2_amd64.deb
sudo apt-get install ./python-serial_3.4-2_all.deb ./python-gtk2_2.24.0-5.1ubuntu2_amd64.deb
wget -c https://trac.chirp.danplanet.com/chirp_daily/LATEST/chirp-daily-20220103.tar.gz
tar -xf chirp-daily-20220103.tar.gz
cd chirp-daily-20220103/
sudo python2 setup.py install
and then launch CHIRP from Applications or Brisk menu.