[PyQt] PyQT5, QML and grid layout problems on OS X.
M Jérôme LAURENS
jerome.laurens at u-bourgogne.fr
Wed Jul 20 21:55:39 BST 2016
I give an answer to my own question explaining why QML2_IMPORT_PATH is sometimes necessary.
When you install pyqt5 from source, quite everything is ok.
You give the location of your qmake tool and indirectly its qml associate folder.
That way pyqt5 knows exactly where to find qml modules as shown by next command:
from PyQt5.QtCore import QLibraryInfo
print(QLibraryInfo.location(QLibraryInfo.Qml2ImportsPath))
which read
[path to your Qt distribution]/5.6/clang_64/qml
Then you can use qml apps out of the box.
On the contrary, when you install from wheel using pip, pyqt5 has no chance to know where your qml modules are.
In that case
from PyQt5.QtCore import QLibraryInfo
print(QLibraryInfo.location(QLibraryInfo.Qml2ImportsPath))
read
[path to your python distribution]/site-packages/PyQt5/Qt/qml
which does not exist.
In order to use qml, you must either use QML2_IMPORT_PATH, QQmlApplicationEngine::addImportPath or properly create the missing folder.
I now have to investigate the next questions.
Jérôme
> Le 19 juil. 2016 à 23:11, M Jérôme LAURENS <jerome.laurens at u-bourgogne.fr> a écrit :
>
> I started from a basic tutorial on using PyQT quick application available at
>
> http://ceg.developpez.com/tutoriels/pyqt/qt-quick-python/02-interaction-qml-python/
>
> Basically it creates a UI with label and buttons and interface a qml file with python.
> My first problem was that python did not find the qml modules, I had to insert something like
>
> engine = QQmlApplicationEngine()
> engine.addImportPath(".../Qt/5.6/clang_64/qml/")
>
> or use QML2_IMPORT_PATH=".../Qt/5.6/clang_64/qml"
>
> First questions : is it the expected way of declaring qml module location ?
> What about other platforms ? (my app will target iOS, android…)
> What about deployment ?
>
More information about the PyQt
mailing list