How can I add a missing PyQt5 modules on Raspberry Pi

Viewed 7277

I am using PyQt5 version 5.7, python 3.5.3 and raspbian. My problem is that in my code some modules of PyQt5 get recognized and produce no error and some do.

The error I get: ImportError: cannot import name 'QMultimedia'

So why does QtCore/Widgets/Gui get reconized but not QMultimedia? Do I need to install some extra packages? Do I need to reinstall and do something special? This might be a trivial question but please help me.

Note: I also tried: from PyQt5 import QtMultimedia

import numpy as np
import sys
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QMultimedia
from PyQt5 import QCameraInfo
from PyQt5 import QVideoWidget
from PyQt5 import QMediaObject
from PyQt5.QtCore import pyqtSignal

class Camera():
    def iniCamera():
        cam = QCamera()
        caminfo = QCameraInfo(cam)
        print (caminfo.description)

        if caminfo.isNull() != True:
           cam = QCamera(caminfo.deviceName())
           print (caminfo.description)

if __name__ == '__main__':

    iniCamera()
2 Answers

If you installed the Raspbian pyqt5-dev and pyqt5-dev-tools packages, this will only provide the core PyQt5 modules like QtCore, QtGui, QtWidgets, etc. For other modules like QtMultimedia, you must install separate packages.

If you go to the Raspbian Connect Package List, and look in the Python Packages section, you will find the following extra packages:

  • python3-pyqt5.qsci
  • python3-pyqt5.qtmultimedia
  • python3-pyqt5.qtopengl
  • python3-pyqt5.qtpositioning
  • python3-pyqt5.qtquick
  • python3-pyqt5.qtsensors
  • python3-pyqt5.qtserialport
  • python3-pyqt5.qtsql
  • python3-pyqt5.qtsvg
  • python3-pyqt5.qtwebchannel
  • python3-pyqt5.qtwebkit
  • python3-pyqt5.qtwebsockets
  • python3-pyqt5.qtx11extras
  • python3-pyqt5.qtxmlpatterns

So just use apt-get to install whatever else you need.

Check your site-packages folder to see if this package actually exists.

If you are working behind a virtualenv (which you should), make sure it's activated. Using pip3 freeze, see if PyQt5 is correctly installed.

Then, install a pylint extension, this can help you in future missing packages and other stuff.

Related