ModuleNotFoundError: No module named 'xmodem' on raspberry pi

1.7k views Asked by At

Really new to programming in Python and I am trying to build a flask web app for a raspberry pi that would DNC g-code from a text file over the serial port to an older HASS cnc mill. The mill uses the XMODEM protocol. I have been following the documentation at https://pypi.org/project/xmodem/.

When I run python3 dncPi.py from the command line, I get the following error:

  File "dncPi.py", line 2, in <module>
    from xmodem import XMODEM
ModuleNotFoundError: No module named 'xmodem' 

Runnning pip3 install xmodem shows:

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: xmodem in /home/pi/.local/lib/python3.7/site-packages (0.4.6)

I have checked that /home/pi/.local/lib/python3.7/site-packages is part of the python3 path with:

python3 -c "import sys; print(':'.join(x for x in sys.path if x))"

Here is my dncPi.py code:

import serial
from xmodem import XMODEM
from flask import Flask, render_template, request

ser = serial.Serial('/dev/ttyAMA0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=0, rtscts=0)

def getc(size):
    return ser.read(size) or None

def putc(data):
    return ser.write(data)

modem = XMODEM(getc, putc)

app = Flask(__name__)

@app.route("/")
def index():

    print(request.method)
    if request.method == 'POST':
        if request.form.get('Send NC') == 'Send NC':
            filename = request.form.get('Filename')
            stream = open('/mnt/CNC/DNC/' + filename + '.nc', 'rb')
            status = modem.send(stream, retry=8)
            if status:
                print(filename + ".nc Sent")
            else:
                print(filename + ".nc Send Failure")
        elif request.form.get('Abort') == 'Abort':
            modem.abort()
            print("Aborted")
        else:
            # pass # unknown
            return render_template("index.html")
    elif request.method == 'GET':
        # return render_template("index.html")
        print("No Post Back Call")
    return render_template("index.html")

if __name__ == "__main__":
   app.run(host='0.0.0.0', port=80, debug=True)
1

There are 1 answers

0
drescheg On

tripleee had it correct. I was not expecting sudo to change the environment. sudo pip3 install xmodem fixed it.