No module named 'toml' installing requirements.txt when creating a container

382 views Asked by At

I'm trying to build a container and I have some libraries for Python in the requirements.txt file.

mysqlclient==2.1.0
Django==3.2.12
djangorestframework==3.13.1
djangorestframework_simplejwt==5.0.0
django-cors-headers==3.11.0
WeasyPrint==52.5
requests==2.27.1
django-environ==0.8.1
django_rest_captcha==0.2.0

(all these versions work in the production server)

The problem comes when i make docker build, all the requirements.txt are install just fine, but then appears the following error:

#15 7.296   Installing build dependencies: started
#15 11.12   Installing build dependencies: finished with status 'done'
#15 11.12   Getting requirements to build wheel: started
#15 11.22   Getting requirements to build wheel: finished with status 'done'
#15 11.66 ERROR: Exception:
#15 11.66 Traceback (most recent call last):
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 153, in _main
#15 11.66     status = self.run(options, args)
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 401, in run
#15 11.66     resolver.resolve(requirement_set)
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_internal/legacy_resolve.py", line 202, in resolve
#15 11.66     self._resolve_one(requirement_set, req)
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_internal/legacy_resolve.py", line 368, in _resolve_one
#15 11.66     abstract_dist = self._get_abstract_dist_for(req_to_install)
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_internal/legacy_resolve.py", line 315, in _get_abstract_dist_for
#15 11.66     abstract_dist = self.preparer.prepare_linked_requirement(
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 223, in prepare_linked_requirement
#15 11.66     abstract_dist = _get_prepared_distribution(
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 49, in _get_prepared_distribution
#15 11.66     abstract_dist.prepare_distribution_metadata(finder, build_isolation)
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_internal/distributions/source/legacy.py", line 37, in prepare_distribution_metadata
#15 11.66     self._setup_isolation(finder)
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_internal/distributions/source/legacy.py", line 90, in _setup_isolation
#15 11.66     reqs = backend.get_requires_for_build_wheel()
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_vendor/pep517/wrappers.py", line 151, in get_requires_for_build_wheel
#15 11.66     return self._call_hook('get_requires_for_build_wheel', {
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_vendor/pep517/wrappers.py", line 255, in _call_hook
#15 11.66     raise BackendUnavailable(data.get('traceback', ''))
#15 11.66 pip._vendor.pep517.wrappers.BackendUnavailable: Traceback (most recent call last):
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 63, in _build_backend
#15 11.66     obj = import_module(mod_path)
#15 11.66   File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
#15 11.66     return _bootstrap._gcd_import(name[level:], package, level)
#15 11.66   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
#15 11.66   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
#15 11.66   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
#15 11.66   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
#15 11.66   File "<frozen importlib._bootstrap_external>", line 843, in exec_module
#15 11.66   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
#15 11.66   File "/usr/lib/python3.8/site-packages/pip/_vendor/pep517/build.py", line 6, in <module>
#15 11.66     import toml
#15 11.66 ModuleNotFoundError: No module named 'toml'
#15 11.66
------
executor failed running [/bin/sh -c pip3 install -r requirements.txt]: exit code: 2

I've tried to add toml to the requirements.txt file and add RUN pip3 install toml in the Dockerfile before the RUN pip3 install -r requirements.txt and still doesn't work.

This is the dockerfile:

FROM registry.access.redhat.com/ubi8/ubi:latest

WORKDIR /usr/src/app

RUN yum -y update && \ 
    yum -y install python38 python38-devel redhat-rpm-config cairo pango gdk-pixbuf2 libffi-devel wget gcc openssl-devel bzip2-devel zlib-devel
RUN wget https://repo.mysql.com//mysql80-community-release-el8-3.noarch.rpm
RUN rpm -Uvh mysql80-community-release-el8-3.noarch.rpm

RUN yum clean packages
RUN yum -y install mysql-community-devel.x86_64 
RUN yum -y install nano
RUN pip3 install toml
COPY requirements.txt ./
RUN pip3 install -r requirements.txt
COPY . .
RUN python3 manage.py makemigrations
RUN python3 manage.py migrate

EXPOSE 8000
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
0

There are 0 answers