I know there a many questions and answers on SO for this question, but nothing worked for me.
I installed the newest QT Creator 4.9.2 with Qt 5.13.0 MinGW 32-Bit and MySQLServer 5.5 to compile the QMYSQL driver. I but the driver in the sqldrivers folder and the libmysql.dll in the bin folder.
If I use C++ to connect to the database, everything is working fine, but I doesn't with python.
Additionally I installed on a fresh Python 3.7 32-Bit:
PyQt5: pip install pyqt5 (5.13.0)
mysqlclient: pip install mysqlclient (1.4.2)
mysql-connector: pip install mysql-connector (2.2.9)
and but the driver I compiled before in the sqldrivers folder from PyQt5, because the driver was missing there as well.
My Class:
class SqlConnector(QSqlDatabase):
def __init__(self):
super(SqlConnector, self).__init__()
self.db = self.connect()
def __del__(self):
self.db.close()
def connect(self):
db = QSqlDatabase.addDatabase("QMYSQL")
db.setHostName("hostname")
db.setDatabaseName("database")
db.setUserName("username")
db.setPassword("1234567890")
ok = db.open()
if ok:
print("Connection established")
return db
else:
print("Connection failed: ", db.lastError().text())
return None
def getPools(self):
query = QSqlQuery("SELECT id, name, token, dlxCode FROM AnalysisPool", self.db)
model = QSqlQueryModel()
model.setQuery(query)
return model
Main Method:
from PyQt5.QtSql import QSqlDatabase, QSqlQueryModel, QSqlQuery
from PyQt5.QtWidgets import QApplication, QTableView
if __name__ == "__main__":
app = QApplication(sys.argv)
poolView = QTableView()
poolView.show()
database = SqlConnector()
# poolView.setModel(database.getPools())
sys.exit(app.exec_())
The libraryPaths from PyQt are C:/Python/lib/site-packages/PyQt5/Qt/plugins and C:/Python
The used OS is Windows 10 (1809) 64-Bit and I included in the path variable the MySQLServer lib folder.
I don't know what to do, I have read every SO question about this topic without a working solution for my problem.
For me worked this way: UNinstall package insraled via pip3.
pip3 uninstall PyQt5
Install the native package for your distro (linux case). In my case is Fedora then
Sudo dnf install python3-qt5 python3-qt5-qtbase --allowerasing
Use an option wich lets you overwrite old files like --force or --allowerasing or something equivalent
Related
On ubuntu, I developed an application using pyqt5, but it does not support Chinese input(My sogouPinyin input method cannot show Chinese context menu when I want to type text on my application). My OS supports Chinese input. How to fix it?
install some packages.
sudo apt install fcitx-frontend-qt5 fcitx-libs-qt fcitx-libs-qt5
copy lib to pyqt folder.
sudo cp /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so ${PYTHON_HOME}/lib/site-packages/PyQt5/Qt/plugins/platforminputcontexts/
add os.environ['QT_IM_MODULE'] = 'fcitx' in main file. (maybe not necessary.)
reference
sogouPinyin is based on Fcitx, so for the case of Qt applications the docs indicates that you have to use the flag QT_IM_MODULE:
from PyQt5 import QtWidgets
if __name__ == '__main__':
import sys
import os
os.environ['QT_IM_MODULE'] = 'fcitx'
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
lay = QtWidgets.QVBoxLayout(w)
lay.addWidget(QtWidgets.QLineEdit())
lay.addWidget(QtWidgets.QTextEdit())
w.show()
sys.exit(app.exec_())
After the application is open you must place the focus in an editing widget such as QLineEdit, QTextEdit and press Ctrl + Space to enable it.
But you have to have installed fcitx-qt5 package:
On Ubuntu:
sudo apt-get install fcitx-qt5 fcitx fcitx-frontend-qt5
I try to run a Python script which is a demo from PyForms, which uses PyQt5, SIP and obviously QScintilla.
import pyforms
from pyforms import BaseWidget
from pyforms.controls import ControlText
from pyforms.controls import ControlButton
class Application(BaseWidget):
def __init__(self):
super(Application, self).__init__('Name of the app')
#Definition of the forms fields
self._firstname = ControlText('First name', 'Default value')
self._middlename = ControlText('Middle name')
self._lastname = ControlText('Lastname name')
self._fullname = ControlText('Full name')
self._button = ControlButton('Press this button')
I had a lot of trouble to come to this point. One hurdle was to get the suitable PyQt5-Version in combination with SIP. Now Pydev(Eclipse) prompts me the following:
QScintilla2 not installed
DLL load failed: Die angegebene Prozedur wurde nicht gefunden.
(translation DE -> EN: The given procedure couldn't be found)
QScintilla2 is installed and I tried to reinstall in different versions many times. I have no matter how to fix this with PIP.
The current versions under Windows 8are:
Python: 3.7
PyForms: 3.0.0
AnyQt: 0.0.8
PyQt5: 5.10.1
PyQt5-sip: 4.19.12
QScintilla: 2.10.7
sip: 4.19.8
For people who want to know my previous fix for the PyQt5/sip hurdle: Stackoverflow | Answer from user ntaro
If you need further information, let me know it, please!
I uninstalled and installed the latest versions of
QScintillaPyformsSIPPyQt5
Order: SIP -> PyQt5 -> QScintilla -> Pyforms
Works now!
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.
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"
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.