【问题标题】:Python 3.6.4 dbus import errorPython 3.6.4 dbus 导入错误
【发布时间】:2018-07-31 08:26:12
【问题描述】:

按照另一篇文章中的建议将 /usr/lib/python3/dist-packages 添加到我的 sys.path 后,当我尝试在 python3 中导入 dbus 时出现错误:

>>> import dbus
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/dbus/__init__.py", line 82, in <module>
    import dbus.types as types
  File "/usr/lib/python3/dist-packages/dbus/types.py", line 6, in <module>
    from _dbus_bindings import (
ModuleNotFoundError: No module named '_dbus_bindings'

我尝试用 apt 重新安装 python3-dbus,但无济于事。在尝试完全重置我的 python3-dbus 时意外卸载了 dbus 而不是 python3-dbus,我什至不得不重新安装我的操作系统。我什至从源代码安装了 Python 3.6.4。感谢您提供任何帮助,因为我完全不知道为什么这不起作用。

我的 /usr/lib/python3/dist-packages/dbus/ 目录中的文件:

bus.py         exceptions.py                lowlevel.py  service.py
_compat.py     _expat_introspect_parser.py  mainloop     types.py
connection.py  gi_service.py                proxies.py   _version.py
_dbus.py       glib.py                      __pycache__
decorators.py  __init__.py                  server.py

在我看来,python 正在尝试从文件 _dbus_bindings.py 导入,但它不存在。我在网上查看了这个错误,找不到任何有用的东西。

【问题讨论】:

    标签: python-3.x ubuntu-16.04 dbus


    【解决方案1】:

    我已经解决了这个问题:

    pip3 install dbus-python
    

    【讨论】:

    • 被低估的答案。如果你不能这样做,那么你的问题是你的包回购。
    【解决方案2】:

    如果您通过 ppa 安装了数据包“python3.6”,如下所述:http://ubuntuhandbook.org/index.php/2017/07/install-python-3-6-1-in-ubuntu-16-04-lts,那么您可以使用以下命令将命令 python3 切换回指向 3.5 版的 python:

    sudo update-alternatives --config python3

    我在启动依赖于 python 3.5 的 unity-tweak-tool 时遇到问题,并给了我“No module named '_dbus_bindings'”错误。这个解决方案有帮助,尽管它剥夺了你的 python 3.6。

    【讨论】:

      【解决方案3】:

      我遇到了同样的错误,并尝试了pip install dbus-pythonpip3 install dbus-python,正如针对此“导入 dbus”错误所建议的那样,但一直出现错误。将“import dbus”放在“sys.path.insert(0, “/usr/lib/python3/dist-packages”)”下面解决了这个问题。所以,

      # Below line gave import dbus error!
      import dbus   
      sys.path.insert(0, "/usr/lib/python3/dist-packages")
      

      在“sys.path..”下方放置“import dbus”后问题得到解决:

      # This worked
      sys.path.insert(0, "/usr/lib/python3/dist-packages")
      import dbus
      

      【讨论】:

        猜你喜欢
        • 2018-09-17
        • 1970-01-01
        • 2018-06-09
        • 2018-11-17
        • 2018-04-22
        • 1970-01-01
        • 2018-10-26
        • 2016-05-07
        • 1970-01-01
        相关资源
        最近更新 更多