Pyside6(QT 6.0+)QPSQL驱动程序未加载

发布于 2025-01-23 18:06:20 字数 2828 浏览 0 评论 0原文

我在Windows 10中写了该项目。我使用Postgres数据库。我使用QSQLTableModel显示客户端表。

self.model = QtSql.QSqlTableModel()
self.ui.tableView.setModel(self.model)

现在将设备更改为MacBook M1(Macos Monterey)。问题开始了。安装了psycopg2二进制。我连接到数据库。但是QSQLTableModel不起作用。启动项目时,以下错误显示在Pycharm上:

QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins

终端显示以下:

marcus@MacBook-Air-Marcus ~ % postgres -V                     
postgres (PostgreSQL) 14.2
marcus@MacBook-Air-Marcus ~ % psql -V    
psql (PostgreSQL) 14.2

我创建的链接。

marcus@MacBook-Air-Marcus ~ % brew link --overwrite postgresql
Linking /opt/homebrew/Cellar/postgresql/14.2_1... 4318 symlinks created.

marcus@MacBook-Air-Marcus bin % export PATH=$PATH:/opt/homebrew/Cellar/libpq/14.2/bin
marcus@MacBook-Air-Marcus bin % export PATH=$PATH:/opt/homebrew/opt/libpq/lib  
marcus@MacBook-Air-Marcus bin % echo $PATH          
/opt/homebrew/opt/[email protected]/bin:/opt/homebrew/opt/libpq/bin:/usr/local/opt/libpq/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/opt/homebrew/Cellar/libpq/14.2/bin:/opt/homebrew/opt/libpq/lib

我不知道如何修复它们。

更新 在路径中,添加了qmake文件(/users/marcus/qt/6.3.0/macos/bin)的路径。

marcus@MacBook-Air-Marcus sqldrivers % echo $PATH
/Users/marcus/Qt/6.3.0/macos/bin:/opt/homebrew/opt/[email protected]/bin:/opt/homebrew/opt/libpq/bin:/usr/local/opt/libpq/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/marcus/Qt/6.3.0/Src/qtbase/src/plugins/sqldrivers

文档中指定了以下方法( .io/qt-5/sql-driver.html#qpsql ): 如何在UNIX和MACOS上构建QPSQL插件 您需要安装PostgreSQL客户端库和标头。

要使QMAKE查找PostgreSQL标头文件和共享库,请以以下方式运行QMAKE(假设PostgreSQL客户端安装在 /USR中):

cd $QTDIR/qtbase/src/plugins/sqldrivers
qmake -- PSQL_INCDIR=/usr/include/pgsql
make sub-psql

但是我做不到。打扰一下。我是新手。

marcus@MacBook-Air-Marcus psql % pwd
/Users/marcus/Qt/6.3.0/Src/qtbase/src/plugins/sqldrivers/psql
marcus@MacBook-Air-Marcus psql % qmake -o Makefile /Users/marcus
Cannot read /Users/marcus: file to open is a directory

以下文件在目录中可用

marcus@MacBook-Air-Marcus psql % ls
CMakeLists.txt  main.cpp    qsql_psql.cpp
README      psql.json   qsql_psql_p.h

I wrote the project in Windows 10. I use the Postgres database. I use QSqlTableModel to display the client table.

self.model = QtSql.QSqlTableModel()
self.ui.tableView.setModel(self.model)

Now changed the device to macbook m1 (macOS Monterey). And the problems began. Psycopg2-binary installed. I connect to the database. But the QSqlTableModel doesn't work. When starting a project, the following errors appear on the PyCharm:

QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins

The terminal shows the following:

marcus@MacBook-Air-Marcus ~ % postgres -V                     
postgres (PostgreSQL) 14.2
marcus@MacBook-Air-Marcus ~ % psql -V    
psql (PostgreSQL) 14.2

Link I created.

marcus@MacBook-Air-Marcus ~ % brew link --overwrite postgresql
Linking /opt/homebrew/Cellar/postgresql/14.2_1... 4318 symlinks created.

marcus@MacBook-Air-Marcus bin % export PATH=$PATH:/opt/homebrew/Cellar/libpq/14.2/bin
marcus@MacBook-Air-Marcus bin % export PATH=$PATH:/opt/homebrew/opt/libpq/lib  
marcus@MacBook-Air-Marcus bin % echo $PATH          
/opt/homebrew/opt/[email protected]/bin:/opt/homebrew/opt/libpq/bin:/usr/local/opt/libpq/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/opt/homebrew/Cellar/libpq/14.2/bin:/opt/homebrew/opt/libpq/lib

I can't figure out how to fix them.

UPDATE
In PATH, the path to the qmake file (/Users/marcus/Qt/6.3.0/macos/bin) added.

marcus@MacBook-Air-Marcus sqldrivers % echo $PATH
/Users/marcus/Qt/6.3.0/macos/bin:/opt/homebrew/opt/[email protected]/bin:/opt/homebrew/opt/libpq/bin:/usr/local/opt/libpq/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/marcus/Qt/6.3.0/Src/qtbase/src/plugins/sqldrivers

The following method is specified in the documentation (https://doc.qt.io/qt-5/sql-driver.html#qpsql):
How to Build the QPSQL Plugin on Unix and macOS
You need the PostgreSQL client library and headers installed.

To make qmake find the PostgreSQL header files and shared libraries, run qmake the following way (assuming that the PostgreSQL client is installed in /usr):

cd $QTDIR/qtbase/src/plugins/sqldrivers
qmake -- PSQL_INCDIR=/usr/include/pgsql
make sub-psql

But I can't do it. Excuse me. I'm new to that.

marcus@MacBook-Air-Marcus psql % pwd
/Users/marcus/Qt/6.3.0/Src/qtbase/src/plugins/sqldrivers/psql
marcus@MacBook-Air-Marcus psql % qmake -o Makefile /Users/marcus
Cannot read /Users/marcus: file to open is a directory

The following files are available in the directory

marcus@MacBook-Air-Marcus psql % ls
CMakeLists.txt  main.cpp    qsql_psql.cpp
README      psql.json   qsql_psql_p.h

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔日梦未散 2025-01-30 18:06:20

QPSQL只是LIBPQ库的包装器。您必须在计算机上安装Postgres应用程序,或者使用酿造或下载和安装Postgres.app
然后使您的应用程序知道库在哪里:
例如,如果您

export DYLD_LIBRARY_PATH=/opt/brew/lib

在Postgres的情况下使用Brew Set Environment变量

QPSQL is just a wrapper to libpq library. you must install either Postgres application on your machine either with brew or downloading and installing Postgres.app
Then make your application aware where the library is:
for example if you used brew set environment variable

export DYLD_LIBRARY_PATH=/opt/brew/lib

In case of Postgres.app find the lib path in the content of Postgres.app

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文