Python versions and modules problem

I’m trying try out a script but bump into a missing module thing that I’m trying to sort out. At command prompt python --version gives 2.7.18 but packages offered for the module seem to be python3 (python3.9-lxml in this case). This may be a problem, although py is not familiar to me (so could be anything really). Any suggestions how to proceed?

(edit: moved to category PureOS from L5)

Try python3 instead?

That is the mismatch I’m trying to solve: L5 is using one and the module is offered in the other. Something needs to change but A) which should/could it be, and B) how? It would also be interesting to know why this is so (is there perhaps a mistake or is that intentional)?

I may not be understanding your issue correctly, but I’ve had some distros where python 3 has to be executed explicitly with “python3 script.py”. But maybe the L5 doesn’t have Python 3. If you run " python3 --version" in the terminal does it work?

@JR-Fi : Most Python programs it calling to others python modules to run, so in this case it can be installed the missing module with: pip install python3-lxml

Also sudo apt-get install python-is-python3 will help in some case.

1 Like

Because Python 2 and Python 3 are incompatible programming languages, you should be able to have both installed (if not already the case).

The starting point though, as requested, is

python3 --version

Step forward, step back. The script gives different error when started with python3 (parenthesis missing), which makes me think it may not have been meant to be used with that (not compatible, could this be true? Ver 3.9.2). So, I’m still thinking how to get lxml for 2.7.18, or if there is something missing that it’s not seen/found, even when it is installed.

It seems there are several ways that to have this go bad (and suggestions on those sites still haven’t helped after trying a few). For instance, sudo pip install lxml says requirement already satisfied (/usr/lib/python3/dist-packages (4.6.3)), which confuses me (as it’s not satisfied for 2.7, if I understand this).

(just to add: I don’t use python normally, I’ve only ever run a couple of scripts, so anything related is new to me - hence the confusion)

Is this script a shell script or Python code?

Can you post the script or at least the first dozen lines?

Python. Here’s where the trouble starts (line 10), I think:

import sys
import socket
import urlparse
import json
import Queue
import time

from Queue import Queue

from lxml import etree
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtSvg import *

And after a little trying, using the script with python3 dishes out another missing module (urlparse - see code line 4), which does not come up when trying to start it with python.

OK, another question: Where did this script come from and is it supposed to work with Python 2 or Python 3?

Seems to be a 2.7 or newer. It’s from 2016.

A few steps forward… I’ve found that some script problems are due to python vs. python3 naming changing, so I’ve made a new version fixing those and gotten to the point, that they (or lxml) are no longer the problem, but now I seem to be missing PyQt4 module (PyQt5 doesn’t seem to do the trick). More precisely, if I replace PyQt5 with PyQt5 in the script to import, I get a NameError: name ‘QFrame’ is not defined.

(edit: I think this is becoming an exercise in turning a python2 script into python3 script… I’m not optimistic on doing it by myself)

I’ll try to make notes here of progress, should someone be able to help on trying to make the script python3 compatible (including PyQt4–>PyQt5 required changes). At the moment that means figuring out what to do with SIGNAL (16 of them) and SLOT…

It looks like this is more an issue with this script not being maintained.
This script is written for python 2.7 but python 2 is now deprecated.
p[ython2-lxml is no longer in the current repositories, so you will have to install this manually.
Or you should clean up that script to run under python 3.

good luck.

Thanks - it will be needed. Ay, it’s abandoned, as far as I can tell. It helps that there is a confirmation that they the old lxml is not available. And installing old from source did not seem less difficult (also considering future uses), so I guess I’m trying to learn what Python is now…

Tried to go back to PyQt4 but that was a waste of time - way too difficult to get that to L5 anymore.
So, yeah, I’m going to need someone who speaks python…

How big is this script? Can you tell us what it’s for?

1 Like

314+571 lines (2x .py). I’m trying to make it a surprise and there are a few hurdles so I try not to give false hope. I may have to give in at some point.

I understand. I’m not great at Python myself so I don’t know how much help I can be, but if you hit desperation I can try and at least give your misery some company.

3 Likes

Great news, major step forward - got some help from original script writer, from half way around the world. But, for some reason PureOS on L5 complains missing PyQt5.QtSvg (no problem on my laptop with different distro). Work continues.