无法导入RpiMotorLib

问题描述

我使用以下教程(https://iotdesignpro.com/projects/raspberry-pi-stepper-motor-control-through-a-webpage-using-flask)通过A4988步进驱动器来控制NEMA17步进电机。一旦运行stepper.py程序,我就会收到该错误

跟踪(最近一次通话结束): 文件“ stepper.py”,第4行,在 从RpiMotorLib导入RpiMotorLib ImportError:没有名为RpiMotorLib

的模块

我已安装了20.2.4点。

我是编码的新手,欢迎任何帮助!

from time import sleep
import RPi.GPIO as GPIO
from RpiMotorLib import RpiMotorLib

#define GPIO pins
GPIO_pins = (14,15,18) # Microstep Resolution MS1-MS3 -> GPIO Pin
direction= 20       # Direction -> GPIO Pin
step = 21      # Step -> GPIO Pin

# Declare an named instance of class pass GPIO pins numbers
mymotortest = RpiMotorLib.A4988Nema(direction,step,GPIO_pins,"A4988")

app = Flask(__name__)

#HTML Code 

TPL = '''
<html>
     <img src="https://iotdesignpro.com/sites/default/files/Iot%20Design%20Pro%20logo_0.png" alt="">
    <head><title>Web Page Controlled Stepper</title></head>
    <body>
    <h2> Web Page to Control Stepper</h2>
        <form method="POST" action="test">
            <h5> Use the slider to rotate Stepper Clockwise & Counter-Clockwise  </h5>
            <p>Slider   <input type="range" min="1" max="20" name="slider" /> </p>
            <input type="submit" value="submit" />
        </form>
    </body>
</html>


'''
 
@app.route("/")
def home():

    return render_template_string(TPL)
 
@app.route("/test",methods=["POST"])
def test():
    # Get slider Values
    slider = request.form["slider"]
    print(int(slider))
  
    if (int(slider)>10):
       mymotortest.motor_go(True,"Full",600,int(slider)*.0004,False,.05)
       print("Rotating Clockwise")
    
    if (int(slider)<10):
       mymotortest.motor_go(False,int(slider)*.001,.05)
       print("Rotating Anti-Clockwise")

    
    return render_template_string(TPL)
 
# Run the app on the local development server
if __name__ == "__main__":
    app.run() 

I have pip 20.2.4 installed.
I'm new to coding so any help is welcome!

解决方法

如果您的系统上安装了两个版本的Python-Python2 / Python3,则必须用于Python 3.x pip3。仅使用pip命令时,它将安装适用于Python2的模块。