Can't import QtMultimedia in PyQt 5 on Windows - python

I'm trying to learn PyQt5 + qml, and everything I tried so far works fine, however I've ran into a snag when trying to import QtMultimedia into my qml file results in the following error:
plugin cannot be loaded for module "QtMultimedia": Cannot load library
D:\py35venvQt\lib\site-packages\PyQt5\Qt\qml\QtMultimedia\declarative_multimedia.dll:
The specified module could not be found.
main.qml:
import QtQuick 2.8
import QtQuick.Window 2.2
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1
import QtMultimedia 5.6
Window {
id: root
visible: true
title: 'my pyqt app'
width: 1280
height: 720
}
main.py
if __name__ == '__main__':
def handleStatusChange(status):
if status == QQuickView.Error:
errors = appLabel.errors()
if errors:
print (errors[0].description())
myApp = QApplication(sys.argv)
appLabel = QQuickView()
appLabel.statusChanged.connect(handleStatusChange)
model = models.ActorModel(DB_PATH)
ctxt = appLabel.rootContext()
ctxt.setContextProperty('myModel', model)
appLabel.setSource(QUrl('./qml/main/main.qml'))
try:
sys.exit(myApp.exec_())
except:
print("Exiting")
Without the QtMultimedia import everything works fine, also I've tried all Possible version of QtMultimedia (5.0,5.1 etc). In addition the dll does exist in the correct path.
When searching for a solution online I found some post saying that QtMultimedia is not supported in PyQt5, though I think those posts are too old.
I would appreciate it if someone would shed some light on this situation,
Thank you.
Edit: Python Version 3.5.2 PyQt Version 5.8.
PyQt installation process: new virtualenv -> pip install pyqt5
Edit2: Tried reinstalling to a completely new virtual environment using pip3 install pyqt5 still getting the same error.
Edit3: According to http://www.dependencywalker.com the following dlls can not be found in the dir where declarative_multimedia.dll is:
QT5MULTIMEDIA.DLL QT5QUICK.DLL QT5GUI.DLL QT5QML.DLL QT5CORE.DLL
QT5MULTIMEDIAQUICK_P.DLL
With the exception of QT5MULTIMEDIAQUICK_P.DLL they are all present in the \Lib\site-packages\PyQt5\Qt\bin directory
QT5MULTIMEDIAQUICK_P.DLL is not present at all.
I tried copying all the missing files into \Lib\site-packages\PyQt5\Qt\qml\QtMultimedia to see if it would make any difference. It did not.
I also tried to install PyQt 5 into my proper python 3.5 installation (without virtualenv) and running my code. The result is the same.

I had similar issue on Ubuntu and I solved my problem by adding environment variable LD_LIBRARY_PATH=/home/slav/Apps/Qt5.9.2/5.9.2/gcc_64/lib.
"/home/slav/Apps/Qt5.9.2/5.9.2/gcc_64/lib" here I've install Qt with QtInstaller

maybe You should use pyqt not pyside

Related

PostgreSql, QSqlDatabase: Failed to open Database

My system: Windows 10 Pro 16299, Qt, PyQt 5.11.2, Python 3.6, PostgreSql 10
I tried to use QTableView/QSqlTableModel for in my gui to work with postgresql data. However, I am not able to open the database. I get the error message “Driver not loaded Driver not loaded”.
A new installation of Qt, PostgreSql and PyQt has not solved the problem. I tried also “Dependency Walker” to look for missing dlls, but was not able use the given information.
Do you have an idea how to fix this problem?
As an alternative: Is it possible to use QTableView/QSqlTableModel with psycopg2 (instead of QSqlDatabase)?
Thank you very much in advance!
from PyQt5.QtSql import QSqlDatabase, QSqlQuery, QSqlTableModel
from PyQt5.QtWidgets import QTableView, QApplication
import sys
if __name__ == '__main__':
app = QApplication(sys.argv)
db = QSqlDatabase.addDatabase("QPSQL")
db.setHostName("localhost")
db.setPort(5432)
db.setDatabaseName("Test")
db.setUserName("postgres")
db.setPassword("xxxxx")
if (db.open() == False):
QMessageBox.critical(None, "Error", db.lastError().text())
else:
Print("Connected")
Dependency Walker Screenshot
Find the Postgres driver:
C:\Python\Python36\Lib\site-packages\PyQt5\Qt\plugins\sqldrivers\qsqlpsql.dll
where C:\Python\Python36 is your Python installation directory.
Load this file with dependency walker and check whether libpq.dll and all its dependencies can be found.
Typically the two Postgres folders have to be set on the system path:
C:\Program Files\PostgreSQL\10\bin\
C:\Program Files\PostgreSQL\10\lib\
The dll's version incompatibility (64-bit vs 32-bit) may be one of the probable problems.

Why Python stop working when loads QML file?

I created the QML file with QtCreator to avoid errors
But when I run the python file, it shows a blank window and then immediately says "Python stopped working"
file.py
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(QUrl('main.qml'))
engine.quit.connect(app.quit)
sys.exit(app.exec_())
main.qml
import QtQuick 2.10
import QtQuick.Window 2.2
Window{
visible: true
width: 500
height: 400
}
It just crashes everytime, but it runs ok in QtCreator with C++
I found the solution, is the cache..!
Yesterday I found a folder in this location:
C:\Users\username\AppData\Local\cache\qtshadercache
The thing is that if you create an app in QtCreator, and run it, then if you try to run QML in Python it will crash unless you remove the files in the qtshadercache folder, once the files are removed you can run QML in Python, but you have to remove the files before running QML in Python, only if have used QtCreator before
I hope this could help someone

Does PyQt5/pyqt4 already supports QtVirtualKeyboard with Handwriting Recognition?

I'm working on a desktop application using pyqt5, and I want to use a Virtual Keyboard with Handwriting Recognition. I saw that Qt, QtVirtualKeyboard already support it.
Here's a link!
I got the C++ Qt example code running on QtCreator.
But using python3.5 and PyQt5 it gives this message:
module "QtQuick.VirtualKeyboard" is not installed
import QtQuick.VirtualKeyboard 2.1
How should I go on from here?
Does PyQt5 comes with VirtualKeyboard module? if no How to install it on PyQt5?
for qt desinger you can add only this line on your .py file.
os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"
but If you want use QML with qtvirtualkeyboard;
There is no virtualkeyboard plugin in pyqt5.8, you must be use qt's paths.
For a example, basic steps for pyqt5, qt5.8 and qtvirtualkeyboard installiation on ubuntu:
1.step install qt5.8 with qtvirtualkeyboard
wget
http://download.qt.io/official_releases/qt/5.8/5.8.0/qt-opensource-linux-x64-5.8.0.run
chmod +x qt-opensource-linux-x64-5.8.0.run
./qt-opensource-linux-x64-5.8.0.run
2.step
apt-get install python3 python3-pip
pip3 install pyqt5
3.step
set environmental variables your qt paths on your python code.
import sys, os
os.environ["QT_DIR"] = "/opt/Qt5.8.0/5.8/gcc_64"
os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = "/opt/Qt5.8.0/5.8/gcc_64/plugins/platforms"
os.environ["QT_PLUGIN_PATH"] = "/opt/Qt5.8.0/5.8/gcc_64/plugins"
os.environ["QML_IMPORT_PATH"] = "/opt/Qt5.8.0/5.8/gcc_64/qml"
os.environ["QML2_IMPORT_PATH"] = "/opt/Qt5.8.0/5.8/gcc_64/qml"
os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"
#print(os.environ)
from PyQt5.QtCore import *
from PyQt5 import QtCore
from PyQt5.QtWidgets import *
from PyQt5.QtQuick import *
class keyboardapp(object):
def __init__(self):
self.view = QQuickView()
self.view.setObjectName("View")
#self.view.setFlags(Qt.FramelessWindowHint)
self.view.setSource(QUrl("main.qml"))
self.view.setResizeMode(QQuickView.SizeRootObjectToView)
#self.Screen = self.view.rootObject()
#print("Screen(Root) = " + str(self.Screen))
self.view.show()
app = QApplication(sys.argv)
test = keyboardapp()
sys.exit(app.exec_())
I been stuck with this too, and i am new to Qt
After some researching, and digging in source code, found the solution
You dont need to import it to use it since its a module it will implement itself to every qt input
Well you dont need to install it on PyQt5 but on Qt5 if it is not already come with your Qt package, if you use archlinux you can install it with pacman
pacman -S qt5-virtualkeyboard
If you cannot find it in you os repositories try to build it here is documantation
https://doc.qt.io/qt-5/qtvirtualkeyboard-index.html
Then to use it in your pyqt application, set environmental variable QT_IM_MODULE to "qtvirtualkeyboard" either from your bash or inside the top your script like
import os
os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"

QtQuickControls 2.0 with PyQt5

I setup a virtualenv and installed pyqt5 (PyQt5-5.7-cp35-cp35m-manylinux1_x86_64.whl):
virtualenv -p /usr/bin/python3.5 .
source bin/activate
pip install pyqt5
I created a basic.qml file:
import QtQuick 2.7
import QtQuick.Controls 2.0
Rectangle {
width: 300
height: 100
color: "red"
}
and tried to load it in my python code with:
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQuick import QQuickView
if __name__ == '__main__':
myApp = QApplication(sys.argv)
view = QQuickView()
view.setSource(QUrl('basic.qml'))
view.show()
sys.exit(myApp.exec_())
It fails with
file:///[...]/main.qml:2:1: plugin cannot be loaded for module "QtQuick.Controls": Cannot load library /[virtualenv]/lib/python3.5/site-packages/PyQt5/Qt/qml/QtQuick/Controls.2/libqtquickcontrols2plugin.so: (libQt5QuickTemplates2.so.5: Can't open shared object file: File or directory not found)
import QtQuick.Controls 2.0
^
Process finished with exit code 0
I checked. This file it complains about actually doesn't exist. But how can I install it? Does PyQt5 support QtQuickControls2 at all?
If I switch the import in basic.qml from import QtQuick.Controls 2.0 to import QtQuick.Controls 1.2, it works. But I want to use the new controls.
This looks like a bug in PyQt5. The package is missing both libQt5QuickTemplates2.so and libQt5QuickControls2.so.
Hoping that the Qt 5.7 build contained by the PyQt 5.7 package and the official Qt 5.7 build available at qt.io are built in a fully binary compatible way, one possibility could be to download and install Qt 5.7 from qt.io, and copy the missing libraries into your virtualenv. For example:
$ cp ~/Qt/5.7/gcc_64/lib/libQt5QuickTemplates2.* path/to/lib/python3.5/site-packages/PyQt5/Qt/lib
$ cp ~/Qt/5.7/gcc_64/lib/libQt5QuickControls2.* path/to/lib/python3.5/site-packages/PyQt5/Qt/lib

Installing SIP 4.16.4 and PyQt5.3.1 for Python 3.4 x64 on Windows 8.1

Downloaded SIP 4.16.4.zip(windows source) from riverbankcomputing - Unpacked and ran configure.py from within the folder. Sub-Directories sipgen, sip-lib are now in the Python34 directory along with sipconfig.py and Makefile.
I am unable to run any of the Makefiles either in the sipgen/sip-lib sub folders or in the main Python34 folder. Ran the installer for Py3.4-Qt5.3.1-x64 and the following test code from within PyCharm3.4.1
The code runs with exit code 0, but within the PyCharm editor, the import statements are flagged as
Cannot find reference 'QtCore' in '__init__.py'
and
Cannot find reference 'QtWidgets' in '__init__.py'
The Qt***.pyd (QWidget, QLabel, etc) files from:
Python34\lib\site-packages\PyQt5
used in the code are flagged by PyCharm as Unresolved reference.
My goal is to install PyQt5.3.1x64 for Python 3.4x64 on Windows 8.1 - I have searched extensively and most of the doc/posts I've encountered are for Visual Studio applications or leads off into some tangent that is not applicable.
I'm looking for a concise procedure to install on windows and am not sure if I should also install some base QT by running qt-opensource-windows-x86-1.6.0-6-online.exe installer.
I believe the problem is with not being able to run the make and make install steps for the Windows environment. There is a Makefile in each of the following directories...
Python34: python34\sipgen and python34\siplib
Do I need to run a make and install using each of these and if so how is this done on Windows 8.1?
TEST CODE
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Form(QWidget):
def \__init__(self, parent=None):
super(Form, self).\__init__(parent)
nameLabel = QLabel("Name:")
self.nameLine = QLineEdit()
self.submitButton = QPushButton("&Submit")
buttonLayout1 = QVBoxLayout()
buttonLayout1.addWidget(nameLabel)
buttonLayout1.addWidget(self.nameLine)
buttonLayout1.addWidget(self.submitButton)
self.submitButton.clicked.connect(self.submitContact)
mainLayout = QGridLayout()
# mainLayout.addWidget(nameLabel, 0, 0)
mainLayout.addLayout(buttonLayout1, 0, 1)
self.setLayout(mainLayout)
self.setWindowTitle("Hello Qt")
def submitContact(self):
name = self.nameLine.text()
if name == "":
QMessageBox.information(self, "Empty Field",
"Please enter a name and address.")
return
else:
QMessageBox.information(self, "Success!",
"Hello %s!" % name)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
screen = Form()
screen.show()
sys.exit(app.exec_())
In another post it was suggested that the unresolved references are caused by a bug in PyCharm. The code runs fine but the IDE sets flags throughout for all the Qt components. If anyone else is trying to install sip and Qt5 on windows 8 and needs help contact me and I will be glad to give step by step instructions using Visual Studio Developer Command Prompt.

Categories