相关文章推荐
帅气的领带  ·  【Pyspark ...·  2 周前    · 
近视的橙子  ·  python ...·  2 周前    · 
腼腆的烈马  ·  [Anaconda]——Linux下cond ...·  5 天前    · 
眉毛粗的电梯  ·  python ...·  4 天前    · 
沉着的抽屉  ·  python for循环 ...·  17 小时前    · 
曾深爱过的咖啡  ·  AWS ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm using Raspberry PI for my robotic project. I got this error when try run this code into my raspberry PI through terminal.

#servo_example.py
import servo
servo.servo_setup()
#0 - 180 degrees only!
servo.servo_set_deg(145)
servo.servo_cleanup()

Error message

Traceback (most recent call last):
  File "servo_example.py", line 2, in <module>
    import servo
ImportError: No module named servo

Why I got this error message? How I can fix it?

Did you try pip? You have enough rep on this site that I am surprised that when your program complained that your module didn't exist your first thought wasn't "is this installed?". – SethMMorton Jun 8, 2014 at 1:51

You have named your script servo.py. This means that when you import servo, you are importing your own script. It doesn't have a function named servo_setup so you get an error. You can't import the system's servo.py while your own script is named servo.py. Solution: name your script something else.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.