Python 如何解决 ImportError: No module named 'dbus'?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37521162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:30:23  来源:igfitidea点击:

How solve ImportError: No module named 'dbus'?

pythonpython-2.7python-3.xdbusqtdbus

提问by B nM

I have installed anaconda4on my ubuntu and I have these modules on my Python:

我已经安装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)

I tried installing dbus-python (1.2.4)and pydbus (0.2), however, neither of them works!

我尝试安装dbus-python (1.2.4)pydbus (0.2),但是,他们都没有工作!

After testing a simple program in python 3.5.1, an error appeared:

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

import dbus
system_bus = dbus.SystemBus()

ImportError: No module named 'dbus'

When I use pydbusin Python 2.7.11 and 3.5.1:

当我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)

I get this error:

我收到此错误:

ImportError: No module named repository

The only thing that works is this examplewith PyQT4which I don't have any tutorial for.

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

What is the problem? Is it my installation or something else?

问题是什么?是我的安装还是别的什么?

回答by Amit Chahar

I don't know about installing dbus in anaconda but you can install it using apt-get in ubuntu .

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

sudo apt-get install python-dbus

I tried with pip earlier but that didn't work for me.

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

回答by Arun K

Try this for Python 3.6 32 bit version

在 Python 3.6 32 位版本上试试这个

pip install dbus-python

回答by Neill Herbst

I'm not sure how you installed the modules but this error most likely occurs because the module is not installed or not installed correctly. I would recommend the following for installing a module.

我不确定你是如何安装模块的,但这个错误很可能是因为模块没有安装或安装不正确。我会推荐以下安装模块。

pip install dbus

pip install dbus

or since you have anaconda this will also work

或者因为你有 anaconda 这也可以

conda install dbus

conda install dbus

If you are able to access and download the source code for instance on GitHub you can try the following two methods. Navigate to the source code directory then run the following commands in the terminal:

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

pip install setup.py

or

或者

python setup.py build
python setup.py install

For more on installing packages from source distributions see thispage.

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

回答by azhar22k

I encountered same problem while installing notify2in python3I was on MacOS 10.12 resolved using

我遇到过同样的问题,而安装notify2python3我在MacOS 10.12利用解决

brew install dbus

回答by Chetan Malhotra

Just do

做就是了

sudo apt-get install python-dbus

on debian based os(ubuntu in your case) or

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

brew install dbus

on MacOSX

在 MacOSX 上

回答by HoNgOuRu

I had the same problem when running an application called zeitgeist-explorer, but solved it by installing python2-dbus because the system was using version 3.5 and the application needed the 2 something version. check this post if you are getting an error like this one fix import error no module named dbus

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

回答by LEW21

pydbus requires python-gi (or python3-gi in the case of Python 3). And pydbus 0.2 is really outdated, 0.5.1 is the current version.

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

回答by Garry S

Try re-installing dbus-python. Also try on another virtual environment.

尝试重新安装 dbus-python。还可以尝试另一个虚拟环境。