Python-ImportError:没有名为伺服的模块
我在机器人项目中使用覆盆子PI。我在尝试通过终端将此代码运行到我的raspberry PI时遇到了此错误Python-ImportError:没有名为伺服的模块,python,raspberry-pi,Python,Raspberry Pi,我在机器人项目中使用覆盆子PI。我在尝试通过终端将此代码运行到我的raspberry PI时遇到了此错误 #servo_example.py import servo servo.servo_setup() #0 - 180 degrees only! servo.servo_set_deg(145) servo.servo_cleanup() 错误消息 Traceback (most recent call last): File "servo_example.py", line 2,
#servo_example.py
import servo
servo.servo_setup()
#0 - 180 degrees only!
servo.servo_set_deg(145)
servo.servo_cleanup()
错误消息
Traceback (most recent call last):
File "servo_example.py", line 2, in <module>
import servo
ImportError: No module named servo
为什么我会收到这个错误消息?如何修复它?您已将脚本命名为servo.py。这意味着,当您导入伺服时,您正在导入自己的脚本。它没有名为servo_setup的函数,因此会出现错误。当您自己的脚本名为servo.py时,无法导入系统的servo.py。解决方案:将脚本命名为其他名称。请不要这样做。我的答案现在不是你问题的答案。伺服安装了吗?如何安装伺服?你试过了吗?你在这个网站上有足够的代表,我很惊讶当你的程序抱怨你的模块不存在时,你的第一个想法是没有安装这个吗?。