PyQt6 module not found

How does one access the Python library files that have been installed in /usr/local/lib/python3.10/dist-packages/PyQt6/bindings?

Some pages on the Internet say these libraries are installed in “site-packages”. That is not true for my install. It uses “dist-packages”.

I installed PyQt6 using “pip install PyQt6”.

When using this:
from PyQt6.QtWidgets import (QApplication, QWidget, QVBoxLayout, QPushButton,
QTextEdit, QTreeWidget, QTreeWidgetItem, QScrollArea)
from PyQt6.QtCore import Qt

I get “ModuleNotFoundError: No module named ‘PyQt6’”

Hello,

can you re-try with:

py -m pip install library_name_here

You might also have to type it in as (all lower case):

pip install pyqt6
or 
py -m pip install pyqt6

On a related note, a good IDE such as PyCharm has pip built-in so that you don’t have to manually type the importing of a module package. For example, with PyCharm, you just type the name of the library package in question, and the name will appear in the drop-menu. You click the Install Package button and it will install it for you.

It’s an option to consider.

If you need additional hep with this package, you can try going to this forum:

Paul is guessing that the version pip you ran does not match the version of python you run. I think you are on a debian or ubuntu system, is that right

In which case the command to run will be

python -m pip install PyQt6

But you may find that you can install pyqt6 that is package by debian/ubuntu and not need to use pip at all.

Try adding the following instructions prior to importing the PyQt6 module package above.

   # Add this directory to your PATH (where Python looks for module packages)
   import sys
   sys.path.append(r'C:/usr/local/lib/python3.10/dist-packages') 

   from PyQt6.QtWidgets import (QApplication, QWidget, QVBoxLayout, QPushButton,
   QTextEdit, QTreeWidget, QTreeWidgetItem, QScrollArea)
   from PyQt6.QtCore import Qt

This is automatic for distributions that use dist-packages.
I assume, Paul you are not a user of such systems.

Roger that, over.

You are correct. I am using Linux Mint 22 with Ubuntu 24.04 LTS.

This does not work:

python -m pip install PyQt6

python3 -m pip install PyQt6
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.

If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.

If I try installing: apt install python3-pyqt6 or python3-qt6 it reports no such package exists.

python3 --version
Python 3.12.3

Despite 3.12.3 being installed “pip3” installs PyQt6 in /usr/local/lib/python3.10/dist-packages

So, I downloaded the .deb file from this site: UbuntuUpdates - Package "python3-pyqt6" (noble 24.04) and it refuses to install due to a dependency issue:

Dependency is not satisfiable: python3-pyqt6.sip (>=13.6)

This is crazy! I have Python 3.12 installed (which I think satisfies the > requirement).

And if I do this: pip3 install PyQt6-sip
Requirement already satisfied: PyQt6-sip in /usr/local/lib/python3.10/dist-packages (13.8.0)

I am sure pyqt6 is available to be installed. I will have to setup a vm and check what it is called. (I am a fedora user and only rarely use debian/ubuntu).

Debian was behind the change that forces you to use venv for ANY pip installed package. You could try creating a venv and install pyqt6 from pypi. But a ubuntu package pyqt6 would be best.

Mike,

python3-pyqt6 is available in the Ubuntu 24.04 repos, as you can see here: https://packages.ubuntu.com/noble/python3-pyqt6

I am not familiar with Linux Mint, but the package does not appear to be available from their repos: Repository - Linux Mint

This is most likely because “pip3” on your system is actually /usr/local/bin/pip3, which in turn is actually /usr/local/lib/python3.10/dist-packages/pip. Exactly how this came to be is difficult to say. It depends entirely on how you installed python3.10 and python3.12, respectively.

If you want to be sure that you are using a specific version of python, and only installing and using packages for that version, the way to do that is to use a venv.

python3.12 -m venv myvenv creates a new venv called myvenv.

source myvenv/bin/activate activates the venv.

Once activated, you can install whatever packages you need using pip. Those packages will only be available with that venv.

1 Like