firemail
标题: PythonQt [打印本页]
作者: Qter 时间: 2018-4-4 16:28
标题: PythonQt
https://www.cnblogs.com/xia-weiwen/p/7932379.html
在Qt(C++)中与Python混合编程,可以使用PythonQt库。
网站首页:
下载页面:
作者: Qter 时间: 2018-4-11 14:23
本帖最后由 Qter 于 2018-4-11 14:49 编辑
http://pythonqt.sourceforge.net/Building.html
PythonQt requires at least Qt 4.6.1 and Python 2.6.x/2.7.x or Python 3.3.
To compile PythonQt, you will need a python developer installation which includes Python's header files and the python2x.[lib | dll | so | dynlib].
The recommended way to build PythonQt is to use the QMake-based *.pro file. The build scripts a currently set to use Python 2.6. You may need to tweak the build/python.prf file to set the correct Python includes and libs on your system.
On Linux, you need to install a Python-dev package. If Python can not be linked or include files can not be found, you probably need to tweak build/python.prf
To build PythonQt, just do a:
> cd PythonQtRoot
> qmake
> make all
The tests and examples are located in PythonQt/lib. You should add PythonQt/lib to your LD_LIBRARY_PATH so that the runtime linker can find the *.so files.
以下是deepin 15下的编译
https://sourceforge.net/projects/pythonqt/
下载PythonQt3.2解压后,执行如下命令
> qmake
> make all
/usr/bin/ld: 找不到 -lpulse-mainloop-glib
/usr/bin/ld: 找不到 -lpulse
解决:
sudo find / -name libpulse.so*
然后cp /usr/lib/x86_64-linux-gnu/libpulse.so. /usr/lib/libpulse.so
sudo find / -name libpulse-mainloop-glib.so*
选择其中一个执行cp /usr/lib/x86_64-linux-gnu/libpulse-mainloop-glib.so.0.0.5 /usr/lib/libpulse-mainloop-glib.so
编译完成后,结果都生成在PythonQt3.2/lib/ 中
这里启动程序,报如下错误:
PythonQtTest: error while loading shared libraries: libPythonQt-Qt5-Python2.7.so.3: cannot open shared object file: No such file or directory
添加 PythonQt/lib 路径到 LD_LIBRARY_PATH 变量中
vi ~/.bashrc
添加 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/PythonQt3.2/lib
. ~/.bashrc
作者: Qter 时间: 2018-4-12 10:22
本帖最后由 Qter 于 2018-4-12 10:59 编辑
参考测试用例,创建自己的项目
由于相关路径没有包含,参考示例,把相关配置信息添加到 .pro文件中- include (./build/PythonQt.prf )
- include (./build/PythonQt_QtAll.prf )
- INCLUDEPATH +="/home/hechengjin/program/PythonQt3.2/src"
- INCLUDEPATH +="/home/hechengjin/program/PythonQt3.2/extensions/PythonQt_QtAll"
- INCLUDEPATH +="/usr/include/python2.7"
复制代码 另外还会报 No module named requests
由于机器上把requests安装在dist-packages目录中,如:/usr/lib/python2.7/dist-packages
所以找不到,下载安装包,放到python2.7同级目录中
下载地址 https://www.lfd.uci.edu/%7Egohlke/pythonlibs/
requests‑2.18.4‑py2.py3‑none‑any.whl 找这个文件,下载后,.whl改为.zip
把requests和requests-2.18.4.dist-info都放到/usr/lib/python2.7目录下
修改文件权限:
chmod -R 777 requests/
chmod -R 777 requests-2.18.4.dist-info/
再次执行自己的程序,报:"No module named urllib3"
同样的方法下载 urllib3‑1.21.1‑py2.py3‑none‑any.whl
# chmod -R 777 urllib3/
# chmod -R 777 urllib3-1.21.1.dist-info/
"No module named chardet"
chardet‑3.0.4‑py2.py3‑none‑any.whl
chmod -R 777 chardet/
"No module named certifi"
certifi-2018.1.18-py2.py3-none-any.whl
"cannot import name utils" from . import utils 不知道在哪个文件中可以用 sudo pip install utils
utils-0.9.0-py2.py3-none-any.whl
https://pypi.python.org/pypi/utils/0.9.0#downloads
chmod -R 777 utils/
也不是上面这个,而是当前requests下的/usr/lib/python2.7/requests/utils.py
把 INCLUDEPATH +="/usr/lib/python2.7/requests" 也加入到 .pro文件中
也不对
....
作者: Qter 时间: 2018-4-12 11:03
QT使用PythonQt添加输出- PythonQt::init();
- pyq=PythonQt::self();
- pyMainModule = pyq->getMainModule();
- // connect output signals
- connect(pyq,&PythonQt::pythonStdOut, this, &MainWindow::qcout);
- connect(pyq,&PythonQt::pythonStdErr, this, &MainWindow::qcout);
复制代码初始化之后添加connect,同时添加一个自定义的槽用于承载显示
注意connect中使用Python::self()会导致connect无效,需要自己定义一个PythonQt指针
- public slots:
- void qcout(const QString& qs);
复制代码 https://blog.csdn.net/my393661/article/details/79327210
欢迎光临 firemail (http://firemail.wang:8088/) |
Powered by Discuz! X3 |