synesthesiam / rhasspy

Rhasspy voice assistant for offline home automation
https://rhasspy.readthedocs.io
MIT License
950 stars 101 forks source link

Issue using RPI.GPIO Module in custom python scripts #229

Closed zackbcom closed 4 years ago

zackbcom commented 4 years ago

I'm currently running the docker image on a Raspberry Pi 3. I've installed the RPI.GPIO module with the command apt install python3-rpi.gpio and made the container privileged to have access to the GPIO Pins.

Once I try to import the RPi Module into the Custom script for Intent Handling I'm receiving this error in the console:

rhasspy    | DEBUG:CommandIntentHandler:['/profiles/en/command.py']
rhasspy    | Traceback (most recent call last):
rhasspy    |   File "/profiles/en/command.py", line 7, in <module>
rhasspy    |     import RPi.GPIO as GPIO
rhasspy    | ModuleNotFoundError: No module named 'RPi'
rhasspy    | ERROR:CommandIntentHandler:in_started
rhasspy    | Traceback (most recent call last):
rhasspy    |   File "/usr/share/rhasspy/rhasspy/intent_handler.py", line 328, in in_ready
rhasspy    |     self.command, check=True, input=json_input, stdout=subprocess.PIPE
rhasspy    |   File "/usr/lib/python3.7/subprocess.py", line 512, in run
rhasspy    |     output=stdout, stderr=stderr)
rhasspy    | subprocess.CalledProcessError: Command '['/profiles/en/command.py']' returned non-zero exit status 1.

Running the command python3 /profiles/en/command.py < testing_json_payload.json inside the running docker works just fine using the imported RPi Module.

Once I try using it in the custom script it doesn't see the module.

Is there a specific way to install the needed modules to be available in the sub-process?

Custom Script: https://hastebin.com/edejubejid.py

Version: 2.4.20

zackbcom commented 4 years ago

Found that I needed to add it to the Virtualenv. If anyone comes across this post here is how to add it to the docker.

Dockerfile


WORKDIR /usr/share/rhasspy

RUN apt-get update &&  \
  apt-get install -y build-essential

RUN /usr/share/rhasspy/.venv/bin/pip install RPi.GPIO

ENTRYPOINT ["/run.sh"]

Docker-compose:

services:
  rhasspy:
    container_name: rhasspy
    build: ./dockerfiles/rhasspy
    restart: always
    volumes:
      - "$HOME/.config/rhasspy/profiles:/profiles"
    ports:
      - "12101:12101"
    devices:
      - "/dev/snd:/dev/snd"
      - "/dev/gpiomem:/dev/gpiomem"
    command: --user-profiles /profiles --profile en