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 #...
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,
3 Answers
just change to sudo pip3 install wiringpi. Thats happen because the python interpreter is V2.7
Open a terminal, then
type this:
sudo apt-get python-dev python-pip
then this:
sudo pip install wiringpi
or if the 2nd line of code doesn't work then type this:
sudo pip install wiringpi2
if you install wiringpi2, instead of "import wiringpi", you must type "import wiringpi2"
This solved my issue! Hope it helps!
I believe wiring pi wont work with higher versions of python. Wiringpi 2 is supporting versions higher than 2.7 but wont work with 3.4. Depending of your version you have a few options:
- Use python 2.7
- Use an alternative like rpio