0

i am trying to use Docker for an Django project but i got an issue when i try to build a image. the Dockerfile :

# pull the official base image
FROM python:3.8.3-alpine

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install dependencies
RUN pip install --upgrade pip 
COPY ./requirements.txt /usr/src/app
RUN pip install -r requirements.txt

# copy project
COPY . /usr/src/app

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]`

the requirements.txt file:

asgiref==3.4.1 certifi==2022.12.7 cffi==1.15.0 charset-normalizer==3.1.0 cryptography==35.0.0 distlib==0.3.6 Django==3.2.9 django-crispy-forms==1.13.0 django-extensions==3.1.5 django-sslserver==0.22 filelock==3.10.0 idna==3.4 mysqlclient==2.1.1 paho-mqtt==1.6.1 platformdirs==3.1.1 pycparser==2.21 pyOpenSSL==21.0.0 PyQt5==5.15.7 PyQt5-Qt5==5.15.2 PyQt5-sip==12.11.0 pytz==2021.3 requests==2.28.2 six==1.16.0 sqlparse==0.4.2 urllib3==1.26.14 virtualenv==20.21.0 Werkzeug==2.0.2

the problem at the terminal :

  Downloading mysqlclient-2.1.1.tar.gz (88 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 88.1/88.1 kB 3.9 MB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      mysql_config --version
      /bin/sh: mysql_config: not found
      mariadb_config --version
      /bin/sh: mariadb_config: not found
      mysql_config --libs
      /bin/sh: mysql_config: not found
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-p4jxebcw/mysqlclient_30d2d8c61a2245239a1308ab8f3dd8ea/setup.py", line 15, in <module>
          metadata, options = get_config()
        File "/tmp/pip-install-p4jxebcw/mysqlclient_30d2d8c61a2245239a1308ab8f3dd8ea/setup_posix.py", line 70, in get_config
          libs = mysql_config("libs")
        File "/tmp/pip-install-p4jxebcw/mysqlclient_30d2d8c61a2245239a1308ab8f3dd8ea/setup_posix.py", line 31, in mysql_config
          raise OSError("{} not found".format(_mysql_config_path))
      OSError: mysql_config not found
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

here for pic

is anyone had the same issue ?

maybe i should not have a requirements.txt file ?

erik258
  • 14,701
  • 2
  • 25
  • 31
santa
  • 1
  • 3
  • please don't paste screenshots of text. Copy the text itself and paste as text – erik258 Mar 18 '23 at 15:56
  • for the requirements file u meant ? – santa Mar 18 '23 at 16:02
  • Any and all text should be pasted as text unless its rendered appearance is part of the question. Your terminal text does not include the root cause of the error. Include the rest of the error – erik258 Mar 18 '23 at 16:03
  • 1
    i edit it. and thats all the error that i get from the terminal – santa Mar 18 '23 at 16:08
  • 1
    You probably miss binary for MySQL or the toolchain to compile it. Anyway it is impossible to tell based on log parts you published (next time copy paste the whole thing). As a hint you should first try to make an image with `python-3.10-bulleyes` to check out missing deps then it will be easier to focus on alpine image that are slim and more complex to setup. – jlandercy Mar 18 '23 at 16:11

1 Answers1

1

OSError: mysql_config not found

You need to install the mysql client package before running pip.. Add a line as such in your docker.

RUN apk add --no-cache mysql-client

Most python packages are pure python, but it's not uncommon for them to require system libraries. This is one such example where something "outside" of python has to be installed.

erik258
  • 14,701
  • 2
  • 25
  • 31
  • i just deleted mysqlclient from the requirements.txt file. but i have another problem with PyQt5: – santa Mar 18 '23 at 16:24