skip to Main Content

I’m trying to dockerize my django project. When i run "docker build -t django_project" i get following error:

18.82   Building wheel for twisted-iocpsupport (pyproject.toml): started
19.23   Building wheel for twisted-iocpsupport (pyproject.toml): finished with status 'error'
19.24   error: subprocess-exited-with-error
19.24
19.24   × Building wheel for twisted-iocpsupport (pyproject.toml) did not run successfully.
19.24   │ exit code: 1
19.24   ╰─> [13 lines of output]
19.24       running bdist_wheel
19.24       running build
19.24       running build_ext
19.24       building 'twisted_iocpsupport.iocpsupport' extension
19.24       creating build
19.24       creating build/temp.linux-x86_64-cpython-39
19.24       creating build/temp.linux-x86_64-cpython-39/twisted_iocpsupport
19.24       gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Itwisted_iocpsupport -I/usr/local/include/python3.9 -c twisted_iocpsupport/iocpsupport.c -o build/temp.linux-x86_64-cpython-39/twisted_iocpsupport/iocpsupport.o
19.24       twisted_iocpsupport/iocpsupport.c:1210:10: fatal error: io.h: No such file or directory
19.24        1210 | #include "io.h"
19.24             |          ^~~~~~
19.24       compilation terminated.
19.24       error: command '/usr/bin/gcc' failed with exit code 1
19.24       [end of output]
19.24
19.24   note: This error originates from a subprocess, and is likely not a problem with pip.
19.24   ERROR: Failed building wheel for twisted-iocpsupport
19.24 Successfully built autobahn
19.24 Failed to build twisted-iocpsupport
19.24 ERROR: Could not build wheels for twisted-iocpsupport, which is required to install pyproject.toml-based projects
19.70
19.70 [notice] A new release of pip is available: 23.0.1 -> 23.3.1
19.70 [notice] To update, run: pip install --upgrade pip
------
Dockerfile:13
--------------------
  11 |     # Copy the requirements file into the container and install the Python dependencies
  12 |     COPY requirements.txt /app/
  13 | >>> RUN pip install --no-cache-dir -r requirements.txt --no-dependencies
  14 |
  15 |     # Copy the entire project directory into the container
--------------------
ERROR: failed to solve: process "/bin/sh -c pip install --no-cache-dir -r requirements.txt --no-dependencies" did not complete successfully: exit code: 1

My requirements.txt:

asgiref==3.7.2
attrs==23.1.0
autobahn==23.6.2
Automat==22.10.0
cffi==1.16.0
channels==4.0.0
constantly==23.10.4
cryptography==41.0.5
daphne==4.0.0 
Django==4.2.7
hyperlink==21.0.0
idna==3.4
incremental==22.10.0
pyasn1==0.5.0
pyasn1-modules==0.3.0
pycparser==2.21
pyOpenSSL==23.3.0
python-decouple==3.8
service-identity==23.1.0
six==1.16.0
sqlparse==0.4.4
Twisted==23.10.0
twisted-iocpsupport==1.0.4
txaio==23.1.1
typing_extensions==4.8.0
tzdata==2023.3
zope.interface==6.1

Dockerfile:

FROM python:3.9.18

ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE django_project.settings  

WORKDIR /app

COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

COPY . /app/

EXPOSE 8000

CMD ["gunicorn", "django_project.wsgi:application", "--bind", "0.0.0.0:8000"]  

Python version 3.9.18.

The problem is that daphne is trying to install the twisted-iocpsupport dependency. How to fix it and dockerize django project?

UPD:
added Dockerfile

2

Answers


  1. This problem usually occurs because of the overlapping versions of your dependencies. You might want to relax the dependency version and let pip choose it. You can try to remove the version for the library from the requirements.txt

    Change
    twisted-iocpsupport==1.0.4
    To
    twisted-iocpsupport

    Login or Signup to reply.
  2. Ehh; I normally just delete that dependency from the requirements.

    It’s not really nescessary.
    I don’t know why; probably some missing libraries on linux, but it always fails on Docker. Removing it is quick and dirty, but it works.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search