【问题标题】:No module named 'dbus.mainloop.pyqt5' even if all dependencies seem to be installed即使似乎安装了所有依赖项,也没有名为“dbus.mainloop.pyqt5”的模块
【发布时间】:2019-10-21 02:04:19
【问题描述】:

我正在尝试使用 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'

在虚拟环境中

我也试过 venv。但是,我必须接受系统范围的软件包,因为我找不到与 python3-dbus.mainloop.pyqt5 等效的 pip。

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.init.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 mainloop 是否有 pip 包?谢谢。


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

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

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

【问题讨论】:

标签: python python-3.x pyqt pyqt5 dbus


【解决方案1】:

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

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

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

glib 与 Gtk 解耦,所以我想没关系。

【讨论】:

    猜你喜欢
    • 2021-06-28
    • 1970-01-01
    • 2015-08-19
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-29
    • 1970-01-01
    相关资源
    最近更新 更多