python-3.xmoduleraspberry-piimporterrorwiringpi

Python script can't find module


I am new to the world of programming, I want to use this piece of code to move a little servo:

# Servo Control
# Servo Control
import time
import wiringpi

# use 'GPIO naming'
wiringpi.wiringPiSetupGpio()

# set #18 to be a PWM output
wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT)

# set the PWM mode to milliseconds stype
wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)

# divide down clock
wiringpi.pwmSetClock(192)
wiringpi.pwmSetRange(2000)

delay_period = 0.01

while True:
        for pulse in range(50, 250, 1):
                wiringpi.pwmWrite(18, pulse)
                time.sleep(delay_period)
        for pulse in range(250, 50, -1):
                wiringpi.pwmWrite(18, pulse)
                time.sleep(delay_period)

When i run this piece of code in the idle i get the following error:

Traceback (most recent call last):
  File "/home/pi/servo.py", line 3, in <module>
    import wiringpi
ImportError: No module named 'wiringpi'

I did install wiringpi. and i checked for it using:

dpkg --get-selections

I found it between:

wireless-regdb
wireless-tools
wiringpi
wolfram-engine
wolframscript   

Please help with what you can thanks,


Solution

  • just change to sudo pip3 install wiringpi. Thats happen because the python interpreter is V2.7