gpt4 book ai didi

python3即使安装了也无法导入dbus

转载 作者:太空宇宙 更新时间:2023-11-04 04:49:28 25 4
gpt4 key购买 nike

我试图在 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

关于python3即使安装了也无法导入dbus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48726498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com