ModuleNotFoundError: No module named 'requests' in Docker container

Summary

The user is facing a ‘ModuleNotFoundError’ for the ‘requests’ module while running a Docker container for a connector. They have added ‘RUN pip install requests’ to the Dockerfile but are unsure why it failed. The error occurs when the code tries to import ‘requests’ in the connector’s source code.


Question

<@U04SE163WC8> Spec step failed while running with docker with this error ModuleNotFoundError: No module named 'requests'

I have added the RUN pip install requests line to the Dockerfile. But I don’t know why it failed

I see requests ==2.31.0 in pip list.

Traceback (most recent call last):
  File "/airbyte/integration_code/main.py", line 9, in &lt;module&gt;
    from source_appstore_singer import SourceAppstoreSinger
  File "/airbyte/integration_code/source_appstore_singer/__init__.py", line 1, in &lt;module&gt;
    from .source import SourceAppstoreSinger
  File "/airbyte/integration_code/source_appstore_singer/source.py", line 15, in &lt;module&gt;
    from appstoreconnect import Api
  File "/usr/local/lib/python3.9/site-packages/appstoreconnect/__init__.py", line 1, in &lt;module&gt;
    from .api import Api, UserRole
  File "/usr/local/lib/python3.9/site-packages/appstoreconnect/api.py", line 1, in &lt;module&gt;
    import requests
ModuleNotFoundError: No module named 'requests'```

<br>

---

This topic has been created from a Slack thread to give it more visibility.
It will be on Read-Only mode here. [Click here](https://airbytehq.slack.com/archives/C027KKE4BCZ/p1706189430928989) if you want to access the original thread.

[Join the conversation on Slack](https://slack.airbyte.com)

<sub>
["module-notfounderror", "requests", "docker-container", "connector", "pip-install"]
</sub>

Based on the information provided in the extracts, it seems like you have correctly added the RUN pip install requests line to your Dockerfile. However, the error message indicates that the ‘requests’ module is not found when the Docker container is running. One possible reason could be that the ‘requests’ module is installed in a different Python environment and not in the environment where your code is running inside the Docker container. Here’s a sample Dockerfile from the Airbyte tutorial that installs Python dependencies: Dockerfile FROM python:3.9-slim WORKDIR /airbyte/integration_code RUN pip install requests COPY source.py . COPY spec.json . ENTRYPOINT ["python", "/airbyte/integration_code/source.py"] LABEL io.airbyte.name=airbyte/source-stock-ticker-api LABEL io.airbyte.version=0.1.0 ENV AIRBYTE_ENTRYPOINT='python /airbyte/integration_code/source.py' In this Dockerfile, the RUN pip install requests command installs the ‘requests’ module in the Python environment inside the Docker container. If you have followed a similar approach and the error still persists, it might be helpful to check the following: - Ensure that the ‘requests’ module is not being installed in a virtual environment that is not active when the Docker container is running. - Check if there are any errors during the Docker image build process that might prevent the ‘requests’ module from being installed. - Try rebuilding the Docker image after clearing any cached layers to ensure that the ‘requests’ module is installed. If the issue persists, you might want to seek further assistance on the Airbyte forum or Slack channel.

<@U04SE163WC8> l don’t see an issue while installing requests the same error persists.

Sending build context to Docker daemon   38.4kB
Step 1/20 : FROM python:3.9.11-alpine3.15 as base
 ---> df5be861e65d
Step 2/20 : FROM base as builder
 ---> df5be861e65d
Step 3/20 : WORKDIR /airbyte/integration_code
 ---> Using cache
 ---> 2a7ee7b02c48
Step 4/20 : RUN apk --no-cache upgrade     && pip install --upgrade pip     && apk --no-cache add tzdata build-base libffi-dev openssl-dev
 ---> Using cache
 ---> 13472719d896
Step 5/20 : RUN pip install requests
 ---> Using cache
 ---> 8ad592b47051
Step 6/20 : COPY setup.py ./
 ---> Using cache
 ---> 083479f4cb5d
Step 7/20 : RUN pip install pip==21.2.4 poetry==1.7.1 setuptools==57.4.0 wheel==0.37.0
 ---> Using cache
 ---> 41e9b1183924
Step 8/20 : RUN pip install --no-build-isolation --prefix=/install .
 ---> Using cache
 ---> d68fe599f7c1
Step 9/20 : FROM base
 ---> df5be861e65d
Step 10/20 : WORKDIR /airbyte/integration_code
 ---> Using cache
 ---> 2a7ee7b02c48
Step 11/20 : COPY --from=builder /install /usr/local
 ---> Using cache
 ---> 5dac02186ec7
Step 12/20 : COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
 ---> Using cache
 ---> 2b27becc6121
Step 13/20 : RUN echo "Etc/UTC" > /etc/timezone
 ---> Using cache
 ---> 460403e137f3
Step 14/20 : RUN apk --no-cache add bash
 ---> Using cache
 ---> bdc12c6374ab
Step 15/20 : COPY main.py ./
 ---> Using cache
 ---> b7f1242c4fb8
Step 16/20 : COPY source_appstore_singer ./source_appstore_singer
 ---> Using cache
 ---> c6d745086842
Step 17/20 : ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
 ---> Using cache
 ---> 494b859ecbe2
Step 18/20 : ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
 ---> Using cache
 ---> 1b0837b1e422
Step 19/20 : LABEL io.airbyte.version=0.2.6
 ---> Using cache
 ---> 550b2e29f416
Step 20/20 : LABEL io.airbyte.name=airbyte/source-appstore-singer
 ---> Using cache
 ---> 46bd8bd4ec3d
Successfully built 46bd8bd4ec3d
Successfully tagged ghcr.io/company/source-appstore-singer:0.0.4```

A message from http://kapa.ai|kapa.ai

New message text here