Deleting old Python version

I’m having a hell of a time trying to get zap2epg working and in being in contact with the author, it looks like somehow I have Python 2.7 AND Python 3 and also a module called “ElementTree” is missing. According to him, it is a pretty standard module that is normally included with Python 2.7 or Python 3.

Here’s what he said

OK - here’s the other weird thing - you’re still seeing python 2.7 instead of python 3. You’re system is getting confused on which python modules to run.

Does the Vero OSMC version allow you to uninstall python 2.7 and only have python 3 installed?
As you can see in the log - the the current failing issue is the missing ElementTree module. I don’t know why this would be missing as it is a standard python module that should be in the python 2.7 installation. OSMC must be customizing their python installs with only the modules they feel are necessary. --Perhaps someone in the OSMC space know how to add that module?

Is there a way get rid of Python 2.7 (assuming it isn’t needed with the latest version of OSMC) or just reinstalling them. Something has clearly gone wrong and while I dread having wipe out my Vero4K and start fresh, I’m thinking I might have to (as a last resort).

Any advice?

I’m not very confident this will help, but you could try uninstalling all add ons that were disabled by the upgrade, and then going into Settings / System / Add Ons / Manage Dependencies and uninstalling anything that is listed as Orphaned.

Thanks for your suggestion and I can definitely give it a try later tonight, but was hoping for some sort of command to reinstall Python or check the integrity of system files or something.

Having both Python 2.7 and Python 3 installed side by side on the same system is pretty common.

Fair enough, but something is clearly wrong with the Python installation and before I nuke the whole thing, I’d like to try reinstalling Python or somehow checking its integrity.

But Python 2.7 isn’t supported in Kodi v19 any more… right?

Kodi uses it’s own Python interpreter. On some Linux environments (so OSMC might be in that group), it does use the Python version installed, but it is a virtualized instance of Python specifically for Kodi. Even though OSMC has both Python 3.x and Python 2.x, with Kodi 19, Kodi will ONLY use Python3. There is absolutely no way Kodi 19 would be spinning up a Python 2.x environment.

You could try running apt to install python3, but I won’t be surprised if OSMC says it’s already installed.

osmc@osmc-lr:~$ sudo apt install python3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3 is already the newest version (3.7.3-1).
python3 set to manually installed.
The following packages were automatically installed and are no longer required:
  python-apt python-certifi python-chardet python-dbus python-gi python-gobject python-gobject-2 python-idna
  python-pexpect python-pil python-pkg-resources python-ptyprocess python-requests python-six python-unidecode
  python-urllib3 wireless-firmware-osmc
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

If there is no way Kodi 19 is using Python 2.x, is there a similar command to uninstall that version of Python? Is it even advisable to do so?

FYI, I tried running apt and it went as you predicted

osmc@Vero4k:~$ sudo apt install python3
Reading package lists… Done
Building dependency tree
Reading state information… Done
python3 is already the newest version (3.7.3-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
osmc@Vero4k:~$

At first glance this seems to be all working correctly.

SSH onto your machine and open up Python3. Import EmementTree with this command:

import xml.etree.ElementTree as ET

No errors detected for me, it imports just fine.

Maybe set your default version to 3 if it’s trying to use 2: Changing the default python version in Debian - ExitCode 0

If I run $ python -v
It comes back with python 2.7

Maybe you should try python3 rather than python?

I tried this… Does not appear to work. This is the resultant info

osmc@Vero4k:~$ import xml.etree.ElementTree as ET
-bash: import: command not found

I also tried the same command without “as ET” at the end, but the results were the same

Looks like you didn’t open python3 first

I went through the instructions that @pinn73 linked to at https://exitcode0.net/changing-the-default-python-version-in-debian/ and it seems like python is stuck at version 2.7.

Running python -vgives me a huge rundown of info, all of which points to version 2.7.

If I run ls /usr/bin/python*, I seem to have several versions installed.
sshot-5

Continuing with the instructions, I tried running update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 and ...3.7 2 and it gives me a permission error
sshot-6

Just to be sure, I ran python -v again and it’s still stuck on 2.7.

What happens if you just type python3 at the command prompt?

I get this

osmc@Vero4k:~$ python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

So python 3 is installed. When you got that text did you have a prompt like >>> ?
If so try the command to import the tree as above at the prompt

It didn’t appear to do anything…in a good way. It just accepted the command. However, when I run the zap2epg module within Tvheadend, the log mentions no ElementTree in Python 2.7, so for some reason it is stuck on using the old version of Python.

I did previously try to change the update-alternative to give more importance to Python3.7, but it have a permission error.

Did you try importing the tree in python 2.7?