没有名为"dbus.mainloop.pyqt5"的模块,即使似乎安装了所有依赖项



我正在尝试使用DBUS作为PyQt5的主循环。

全系统范围

我在系统范围内(使用 apt、LinuxMint 19、amd64(安装了以下依赖项:

  • python3-pyqt5 版本: 5.10.1+dfsg-1ubuntu2
  • python3-dbus 版本: 1.2.6-1
  • python3-dbus.mainloop.pyqt5 版本: 5.10.1+dfsg-1ubuntu2

尝试一下:

$ python3                                     
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dbus.mainloop.pyqt5 import DBusQtMainLoop
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dbus.mainloop.pyqt5'

在虚拟环境中

我也尝试过静脉。但是,我不得不接受系统范围的软件包,因为我找不到相当于python3-dbus.mainloop.pyqt5的点。

virtualenv --python=/usr/bin/python3  ~/.venvs/python3/testqtdbus5 --system-site-packages
source ~/.venvs/python3/testqtdbus5/bin/activate
$ pip install "pyqt5==5.10" dbus-python
Collecting pyqt5==5.10
  Using cached https://files.pythonhosted.org/packages/ae/4b/c7315ba7a266d493ee50c4597b1b4dea2348896a49115b5192b21adf1a47/PyQt5-5.10-5.10.0-cp35.cp36.cp37-abi3-manylinux1_x86_64.whl
Requirement already satisfied: dbus-python in /usr/local/lib/python3.6/dist-packages (1.2.8)
Collecting sip<4.20,>=4.19.4 (from pyqt5==5.10)
  Using cached https://files.pythonhosted.org/packages/8a/ea/d317ce5696dda4df7c156cd60447cda22833b38106c98250eae1451f03ec/sip-4.19.8-cp36-cp36m-manylinux1_x86_64.whl
ERROR: pyqtwebengine 5.12.1 has requirement PyQt5>=5.12, but you'll have pyqt5 5.10 which is incompatible.
Installing collected packages: sip, pyqt5
  Found existing installation: PyQt5 5.12
    Not uninstalling pyqt5 at /usr/local/lib/python3.6/dist-packages, outside environment /home/vince/.venvs/python3/testqtdbus5
    Can't uninstall 'PyQt5'. No files were found to uninstall.
Successfully installed pyqt5-5.10 sip-4.19.8

正在尝试:

$ ipython                       
/home/vince/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py:925: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
  warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from dbus.mainloop.pyqt5 import DBusQtMainLoop                                             
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-ad501d00de5f> in <module>
----> 1 from dbus.mainloop.pyqt5 import DBusQtMainLoop
ModuleNotFoundError: No module named 'dbus.mainloop.pyqt5'

实际上,我想要 pyqt v5.12,用于 WebEngine。

$ pip install "pyqt5==5.12.2" dbus-python
Collecting pyqt5==5.12.2
  Downloading https://files.pythonhosted.org/packages/6a/f4/6a63aafcee3efd2b156dc835d9c85ca99b24e80f8af89b6da5c46054fe43/PyQt5-5.12.2-5.12.3-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl (61.5MB)
     |████████████████████████████████| 61.5MB 362kB/s 
Requirement already satisfied: dbus-python in /usr/local/lib/python3.6/dist-packages (1.2.8)
Requirement already satisfied: PyQt5_sip<13,>=4.19.14 in /home/vince/.local/lib/python3.6/site-packages (from pyqt5==5.12.2) (4.19.15)
Installing collected packages: pyqt5
  Found existing installation: PyQt5 5.10
    Uninstalling PyQt5-5.10:
      Successfully uninstalled PyQt5-5.10
Successfully installed pyqt5-5.12.2
$ ipython                       
/home/vince/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py:925: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
  warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from dbus.mainloop.pyqt5 import DBusQtMainLoop                                             
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-ad501d00de5f> in <module>
----> 1 from dbus.mainloop.pyqt5 import DBusQtMainLoop
ModuleNotFoundError: No module named 'dbus.mainloop.pyqt5'

dbus.mainloop的版本。初始化.py

In [2]: import dbus.mainloop  
In [3]: help(dbus.mainloop)                                                                        
# File location is: /usr/local/lib/python3.6/dist-packages/dbus/mainloop/__init__.py

所以似乎使用了系统版本。 好的。

我错过了什么?有 dbus 主环路的 pip 包吗?谢谢。


编辑:到目前为止,我可以使用默认值

from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)

但是,如果 Gtk 现在是一个依赖项,那就不令人满意了。

到目前为止,我可以使用默认的 glib 主循环:

编辑:这不适用于Linux以外的其他平台(使用MacOS测试(。

from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)

glib与 Gtk 分离,所以我想没关系。

最新更新