簡體   English   中英

python3即使安裝了也無法導入dbus

[英]python3 Can't import dbus even though it's installed

我正在嘗試在 python3 項目中使用 dbus,但是當我嘗試導入它時,出現錯誤:

>>> import dbus
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dbus'

所以我試圖通過確保為我的 python 3.6 安裝安裝了 dbus 來修復它,但它似乎已經安裝了:

$ sudo apt-get install python3-dbus
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-dbus is already the newest version (1.2.0-3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

我可以在 python 2.7 中導入 dbus 沒有任何問題,但我的 python3 似乎無法找到該模塊,即使它顯示它已經安裝。 我的which python3顯示它安裝在 /usr/local/bin/python3

您可能會收到此錯誤,因為apt-get安裝的模塊的路徑不在您的sys.path 您可以嘗試的一種解決方案是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM