Python3 tied to older version

1k Views Asked by At

Background: I'm currently running Elementary OS Hera(Ubuntu 18.04 LTS). The distribution came with Python 3.6.9. At some point I installed Python 3.7.5...this is when the issue(s) started.

Problem: I'm attempting to install PyQt5 which keeps defaulting to the older version for some reason. I ensured that Python3 was referencing the newer version:

Wick:~$ python3 --version
Python 3.7.5

I also ensured that python3.7 was the primary version:

Wick:~$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.7   2         auto mode
  1            /usr/bin/python3.6   1         manual mode
* 2            /usr/bin/python3.7   2         manual mode

BUT when I run sudo apt-get install -y python3-pyqt5 . It still continues to install to the 3.6 version. This can be verified via:

:~$ python3 -c "from PyQt5.QtCore import QSettings; print('done')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.QtCore'

AND the kicker

:~$ python3.6 -c "from PyQt5.QtCore import QSettings; print('done')"
done

OR

:~$ python3.7 -c "from PyQt5.QtCore import QSettings; print('done')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.QtCore'

Any assistance you can offer is greatly appreciated. I'm losing my mind.

p.s. apologies in advance for being a newbie

2

There are 2 best solutions below

0
Shawn Wick On BEST ANSWER

This was resolved by @chepner:

"I would recommend using a virtual environment created with /usr/bin/python3.7, >then install pyqt5 there using pip rather than trying to install it via your >package manager."

Thanks so much!

0
Ronie Martinez On

The package only depends on python3.6: https://packages.ubuntu.com/bionic/python3-pyqt5. It will be installed because it is a prerequisite.