Проблема с требованием Python statsmodels при сборке образа Docker

#python #docker #numpy #dockerfile #statsmodels

#python #docker #numpy #докерфайл #статмодели

Вопрос:

Я пытаюсь создать образ Docker для пакетного задания AWS, но новое требование (пакет Python statsmodels ) нарушает мой процесс сборки.

requirements.txt строки:

 pandas
numpy
statsmodels
 

Завершено Dockerfile :

 FROM python:3

COPY requirements.txt /home/
COPY .env /home/
COPY src home/src
COPY process.py /home/

WORKDIR /home/
ENV TZ=America/New_York
RUN /usr/local/bin/python -m pip install --upgrade pip
RUN pip install -r ./requirements.txt

ENV PYTHONPATH='.' 
 

Выдержки из журнала ошибок:

 #12 271.7 INFO: pip is looking at multiple versions of <Python from Requires-Python> to determine which version is compatible with other requirements. This could take a while.
#12 288.4 INFO: pip is looking at multiple versions of us to determine which version is compatible with other requirements. This could take a while.
#12 288.4 Collecting us
#12 288.4   Downloading us-2.0.1.tar.gz (13 kB)
#12 288.8   Downloading us-2.0.0.tar.gz (13 kB)
#12 289.3   Downloading us-1.0.0.tar.gz (13 kB)
#12 289.8   Downloading us-0.9.1.tar.gz (13 kB)
#12 290.2   Downloading us-0.9.0.tar.gz (13 kB)
#12 290.6   Downloading us-0.8.0.tar.gz (12 kB)
#12 291.2   Downloading us-0.7.1.tar.gz (12 kB)
#12 291.5 INFO: pip is looking at multiple versions of <Python from Requires-Python> to determine which version is compatible with other requirements. This could take a while.
#12 291.5 INFO: pip is looking at multiple versions of us to determine which version is compatible with other requirements. This could take a while.
#12 291.6   Downloading us-0.7.tar.gz (11 kB)
#12 291.9   Downloading us-0.6.tar.gz (9.9 kB)
#12 292.3   Downloading us-0.5.tar.gz (9.3 kB)
#12 292.7   Downloading us-0.4.tar.gz (9.3 kB)
#12 293.0   Downloading us-0.3.tar.gz (7.5 kB)
#12 293.4 INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. If you want to abort this run, you can press Ctrl   C to do so. To improve how pip performs, tell us what happened here: https://pip.pypa.io/surveys/backtracking
#12 293.4 INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. If you want to abort this run, you can press Ctrl   C to do so. To improve how pip performs, tell us what happened here: https://pip.pypa.io/surveys/backtracking
#12 293.4   Downloading us-0.2.tar.gz (6.9 kB)
#12 294.0   Downloading us-0.1.tar.gz (6.3 kB)
#12 294.4 INFO: pip is looking at multiple versions of statsmodels to determine which version is compatible with other requirements. This could take a while.
#12 294.9 Collecting statsmodels
#12 294.9   Downloading statsmodels-0.12.0.tar.gz (17.5 MB)
#12 297.5   Installing build dependencies: started
#12 309.5   Installing build dependencies: finished with status 'done'
#12 309.5   Getting requirements to build wheel: started
#12 392.2   Getting requirements to build wheel: still running...
#12 400.0   Getting requirements to build wheel: finished with status 'done'
#12 400.1     Preparing wheel metadata: started
#12 401.3     Preparing wheel metadata: finished with status 'done'
#12 401.9   Downloading statsmodels-0.11.1.tar.gz (15.4 MB)
#12 404.2   Installing build dependencies: started
#12 415.7   Installing build dependencies: finished with status 'done'
#12 415.7   Getting requirements to build wheel: started
#12 480.8   Getting requirements to build wheel: still running...
#12 481.5   Getting requirements to build wheel: finished with status 'done'
#12 481.5     Preparing wheel metadata: started
#12 482.6     Preparing wheel metadata: finished with status 'done'
#12 483.1   Downloading statsmodels-0.11.0.tar.gz (15.4 MB)
#12 485.5   Installing build dependencies: started
#12 488.6   Installing build dependencies: finished with status 'error'
#12 488.6   ERROR: Command errored out with exit status 1:
#12 488.6    command: /usr/local/bin/python /usr/local/lib/python3.9/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-_0xxe4fy/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel 'cython>=0.29.14' 'numpy==1.14.5; python_version=='"'"'3.5'"'"'' 'numpy==1.14.5; python_version=='"'"'3.6'"'"'' 'numpy==1.14.5; python_version>='"'"'3.7'"'"'' 'numpy==1.17.5; python_version>='"'"'3.8'"'"'' 'scipy>=1.0'
#12 488.6        cwd: None
#12 488.6   Complete output (13 lines):
#12 488.6   Ignoring numpy: markers 'python_version == "3.5"' don't match your environment
#12 488.6   Ignoring numpy: markers 'python_version == "3.6"' don't match your environment
#12 488.6   ERROR: Cannot install numpy==1.14.5 and numpy==1.17.5 because these package versions have conflicting dependencies.
#12 488.6   
#12 488.6   The conflict is caused by:
#12 488.6       The user requested numpy==1.14.5
#12 488.6       The user requested numpy==1.17.5
#12 488.6   
#12 488.6   To fix this you could try to:
#12 488.6   1. loosen the range of package versions you've specified
#12 488.6   2. remove package versions to allow pip attempt to solve the dependency conflict
#12 488.6   
#12 488.6   ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies
#12 488.6   ----------------------------------------
#12 488.6 ERROR: Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.9/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-_0xxe4fy/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel 'cython>=0.29.14' 'numpy==1.14.5; python_version=='"'"'3.5'"'"'' 'numpy==1.14.5; python_version=='"'"'3.6'"'"'' 'numpy==1.14.5; python_version>='"'"'3.7'"'"'' 'numpy==1.17.5; python_version>='"'"'3.8'"'"'' 'scipy>=1.0' Check the logs for full command output.
------
failed to solve with frontend dockerfile.v0: failed to build LLB: executor failed running [/bin/sh -c pip install -r ./requirements.txt]: runc did not terminate sucessfully
 

Обновлено Dockerfile по комментариям:

 FROM debian:10-slim

# install Python, pip, and misc build needs
RUN apt-get update 
    amp;amp; apt-get install --no-install-recommends -y 
        build-essential 
        python3-dev 
        python3-pip 
        python3-setuptools 
    amp;amp; apt-get clean

# bring in program logic
COPY .env /root/.env  # this may need to go into /root/.env (or a custom user)
COPY src /app/
COPY processer.py submit-processer.py /app/
COPY requirements.txt /app/

# install Python dependencies
RUN pip3 install --no-cache-dir -r /app/requirements.txt

# set env vars
ENV TZ=America/New_York

# running process logic
WORKDIR /app
ENTRYPOINT ["python3", "processer.py"]
 

Журнал ошибок обновленного процесса:

 [ ] Building 0.7s (7/12)                                                        
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 979B                                       0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load metadata for docker.io/library/debian:10-slim          0.6s
 => [internal] load build context                                          0.0s
 => => transferring context: 15.91kB                                       0.0s
 => CANCELED [1/8] FROM docker.io/library/debian:10-slim@sha256:062bbd9a1  0.0s
 => => resolve docker.io/library/debian:10-slim@sha256:062bbd9a1a58c9c5b8  0.0s
 => CACHED [2/8] RUN apt-get update     amp;amp; apt-get install --no-install-r  0.0s
 => ERROR [3/8] COPY .env /root/.env  # this may need to go into /root/.e  0.0s
------
 > [3/8] COPY .env /root/.env  # this may need to go into /root/.env (or a custom user):
------
failed to solve with frontend dockerfile.v0: failed to build LLB: failed to compute cache key: "/#" not found: not found
 

Ответ №1:

Не совсем понятно, почему из вашего файла Dockerfile (я удивлен, что тега 3 недостаточно, чтобы просто выбрать последнюю стабильную версию 3.9.1-buster ), но pip он пытается разрешить зависимости для нескольких версий Python (подразумевая, что в базовом контейнере установлено несколько)

#12 ОШИБКА 488.6: команда выполнена с ошибкой со статусом выхода 1: /usr/local/bin/python /usr/local/lib/python3.9/site-packages/pip install —ignore-installed —no-user —prefix /tmp/pip-build-env-_0xxe4fy/overlay—no-warn-script-location —no-binary:none: —only-binary:none: -я https://pypi.org/simple — setuptools колесо ‘cython>=0.29.14’ ‘numpy==1.14.5; python_version=='»‘»‘3.5′»‘»» ‘ numpy==1.14.5;python_version=='»‘»‘3.6′»‘»» ‘ numpy==1.14.5; python_version>='»‘»‘3.7′»‘»» ‘ numpy==1.17.5; python_version>='»‘»‘3.8′»‘»» ‘ scipy>=1.0’Проверьте журналы для полного вывода команды.

Указание второстепенной версии может устранить эту проблему.

Если вам не нужна конкретная версия 3.8-slim-buster (Debian 10 с Python 3.8 .. на данный момент фактически 3.8.9, хотя это может измениться с исправлением ошибок в этой версии) может быть практичным выбором и исправить это для вас!

 from python:3.8-slim-buster
...
 

Если это не устраняет ошибку, то, скорее всего, ваш 3 тег в порядке, и вместо этого крайне вероятно, что у вас .env проблемы (предположительно, это виртуальная среда Python, которую вы пытаетесь сохранить).

Восстановите venv в контексте вашего контейнера с помощью нового RUN блока, а не COPY того, что есть в вашей хост-системе.


После комментариев, я думаю, стоит попробовать другой файл Dockerfile, который намного больше того, что я бы использовал, по крайней мере, со следующими изменениями

  • база непосредственно из Debian 10 (вы можете найти другой контейнер более эффективный / меньший / какой угодно, но весьма вероятно, что это работает из коробки)
  • установите Python 3 самостоятельно
  • не используйте /home/ в качестве основы
 FROM debian:10-slim

# install Python, pip, and misc build needs
RUN apt-get update 
    amp;amp; apt-get install --no-install-recommends -y 
        build-essential 
        python3-dev 
        python3-pip 
        python3-setuptools 
    amp;amp; apt-get clean

# bring in program logic
COPY .env /app/  # this may need to go into /root/.env (or a custom user)
COPY src /app/
COPY process.py /app/
COPY requirements.txt /app/

# install Python dependencies
RUN pip3 install --no-cache-dir -r /app/requirements.txt

# set env vars
ENV TZ=America/New_York

# running process logic
WORKDIR /app
ENTRYPOINT ["python3", "process.py"]
 

Если это работает

  • использование /home может быть проблематичным (а не /home/someuser/... )
  • может быть что-то странное с python базовым контейнером upstream (я лично никогда его не использовал, хотя это тоже было бы удивительно)

Если это не сработает

  • возможно, вы работаете не в том каталоге, в котором, по вашему мнению, находитесь (т.е. копирование текущего каталога в другой похожий каталог и т.д.)
  • в вашем src может быть что-то странное
  • statsmodels может быть сломан (у него версия 0.12, так что это не совсем необоснованно).

Комментарии:

1. Здравствуйте, спасибо за ваш ответ. При попытке запустить с 3.8-slim-buster помощью , я получаю аналогичную ошибку, но теперь ModuleNotFoundError: No module named 'numpy' . Мой .env в данном случае — это всего лишь две строки, в которых указаны аргументы API Airtable (AIRTABLE_BASE=xxx …), без venv.

2. Таинственный — попробуйте удалить PYTHONPATH и вызвать просто python3 , а не любую ссылку на /usr/local

3. Хм, после удаления PYTHONPATH строки и вызова RUN python3 -m pip install --upgrade pip я возвращаюсь к ошибке, зарегистрированной в начальном сообщении … есть другие идеи?

4. @OJT Я внес большую правку с другим файлом Dockerfile и некоторыми мыслями, которые могут сработать для вас

5. Я обновил содержимое своего файла Dockerfile и журнал ошибок в вопросе. Я не особенно разбираюсь в этом в целом; в чем именно здесь разница и как это может повлиять на работу в среде экземпляра AWS Batch EC2 (например, использование /app/ по сравнению /home/ с каталогом экземпляра, который мы успешно используем в других процессах, связанных с настройкой, которые не требуют statsmodels ?