Rasa-SDK: ModuleNotFoundError: No module named 'requests'

58 Views Asked by At

After create build my Dockerfile

# server.Dockerfile
FROM rasa/rasa-sdk:3.6.2

USER root

COPY ./actions ./app/actions

RUN apt-get update

RUN pip install --no-cache-dir requests

USER 1001

This error was launched in Docker Desktop after run docker run -d -v ${PWD}/actions:/app/actions --net rasa-action-network --name action_server rasa/rasa-sdk:3.6.2

2024-01-22 14:18:00 /opt/venv/lib/python3.10/site-packages/sanic_cors/extension.py:39: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
2024-01-22 14:18:00   SANIC_VERSION = LooseVersion(sanic_version)
2024-01-22 14:18:00 2024-01-22 20:18:00 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2024-01-22 14:18:00 2024-01-22 20:18:00 ERROR    rasa_sdk.executor  - Failed to register package 'actions'.
2024-01-22 14:18:00 Traceback (most recent call last):
2024-01-22 14:18:00   File "/opt/venv/lib/python3.10/site-packages/rasa_sdk/executor.py", line 263, in register_package
2024-01-22 14:18:00     self._import_submodules(package)
2024-01-22 14:18:00   File "/opt/venv/lib/python3.10/site-packages/rasa_sdk/executor.py", line 226, in _import_submodules
2024-01-22 14:18:00     self._import_module(full_name)
2024-01-22 14:18:00   File "/opt/venv/lib/python3.10/site-packages/rasa_sdk/executor.py", line 240, in _import_module
2024-01-22 14:18:00     module = importlib.import_module(name)
2024-01-22 14:18:00   File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
2024-01-22 14:18:00     return _bootstrap._gcd_import(name[level:], package, level)
2024-01-22 14:18:00   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2024-01-22 14:18:00   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2024-01-22 14:18:00   File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2024-01-22 14:18:00   File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2024-01-22 14:18:00   File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2024-01-22 14:18:00   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2024-01-22 14:18:00   File "/app/actions/actions.py", line 11, in <module>
2024-01-22 14:18:00     import requests
2024-01-22 14:18:00 ModuleNotFoundError: No module named 'requests'

Inside actions.py there is the start of the file

snippet of the code

Someone have idea in how to install requests in rasa-sdk in the Dockerfile or as a parameter in compose command?

If you need more information, please let me know to share with you.

1

There are 1 best solutions below

0
datawookie On

I have tweaked your Dockerfile:

FROM rasa/rasa-sdk:3.6.2

USER root

RUN apt-get update && \
    pip install --no-cache-dir requests

COPY ./actions /app/actions

USER 1001

Changes:

  1. Move COPY to end so that image builds quickly when you make code changes.
  2. Change the target for COPY to an absolute path.
  3. Consolidate the two RUN commands.

In actions/actions.py:

import requests

print("Hello!")

Build and run.

docker build -t rasa .
docker run -it rasa

Output:

2024-01-23 05:10:29 INFO rasa_sdk.endpoint  - Starting action endpoint server...
Hello!
2024-01-23 05:10:29 INFO rasa_sdk.endpoint  - Starting plugins...
2024-01-23 05:10:29 INFO rasa_sdk.endpoint  - Action endpoint is up and running on http://0.0.0.0:5055

The docker run command in your question appears to run the base image (rasa/rasa-sdk:3.6.2) rather than your derived image.