17

我已经安装anaconda4在我的 ubuntu 上,并且我的 Python 上有这些模块:

dbus-python (1.2.4)

gi (1.2)

pydbus (0.2)

QtAwesome (0.3.2)
qtconsole (4.2.0)
QtPy (1.0)

sip (4.18)

我尝试安装dbus-python (1.2.4)pydbus (0.2)但是,它们都不起作用!

在python 3.5.1中测试了一个简单的程序后,出现错误:

import dbus
system_bus = dbus.SystemBus()

ImportError: No module named 'dbus'

当我pydbus在 Python 2.7.11 和 3.5.1 中使用时:

from pydbus import SystemBus

bus = SystemBus()
systemd = bus.get(".systemd1")

for unit in systemd.ListUnits():
    print(unit)

我收到此错误:

ImportError: No module named repository

唯一有效的是这个例子PyQT4我没有任何教程。

问题是什么?是我的安装还是其他?

4

8 回答 8

34

试试这个 Python 3.6 32 位版本

pip install dbus-python
于 2018-09-20T04:16:13.730 回答
30

我不知道在 anaconda 中安装 dbus,但您可以在 ubuntu 中使用 apt-get 安装它。

sudo apt-get install python-dbus

我之前尝试过使用 pip ,但这对我不起作用。

于 2016-06-20T16:04:34.267 回答
4

notify2我在python3 使用 MacOS 10.12 上安装时遇到了同样的问题

brew install dbus
于 2016-11-08T17:06:34.030 回答
3

我不确定您是如何安装模块的,但最有可能发生此错误是因为模块未安装或未正确安装。我会推荐以下安装模块。

pip install dbus

或者因为你有 anaconda 这也可以

conda install dbus

如果您能够访问和下载例如 GitHub 上的源代码,您可以尝试以下两种方法。导航到源代码目录,然后在终端中运行以下命令:

pip install setup.py

或者

python setup.py build
python setup.py install

有关从源发行版安装软件包的更多信息,请参阅页面。

于 2016-05-30T08:54:58.123 回答
2

我在运行一个名为 zeitgeist-explorer 的应用程序时遇到了同样的问题,但通过安装 python2-dbus 解决了这个问题,因为系统使用的是 3.5 版本,而应用程序需要 2 个版本。如果您遇到这样的错误,请检查这篇文章一个 修复导入错误没有名为 dbus 的模块

于 2016-07-16T12:55:59.227 回答
1

pydbus 需要 python-gi(或 Python 3 中的 python3-gi)。而且 pydbus 0.2 确实已经过时了,0.5.1 是当前版本。

于 2016-06-01T07:41:51.047 回答
1

做就是了

sudo apt-get install python-dbus

基于 debian 的操作系统(在您的情况下为 ubuntu)或

brew install dbus

在 MacOSX 上

于 2017-10-29T05:02:23.587 回答
0

尝试重新安装 dbus-python。也尝试在另一个虚拟环境中。

于 2020-02-19T21:54:01.647 回答