首页 > 解决方案 > python/flask 应用程序码头化期间的问题

问题描述

这是当前场景、docker 文件、要求和错误。有什么线索吗?这是一个带有烧瓶的大型 Python Web 应用程序,我们希望将其 docker 化。问题发生在 pandas-profiling lib 依赖项安装期间,特别是 kiwisolver。见下文。

Dockerfile:

FROM python:3.8-alpine
RUN adduser -D ddc-user
WORKDIR /ddc
COPY . /ddc
RUN python -m venv venv
RUN venv/bin/pip install --upgrade pip
RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
     && apk --no-cache --update-cache add postgresql-dev g++ linux-headers gfortran libffi-dev openssl-dev gcc build-base bash libpng-dev openblas-dev wget freetype-dev python3-dev py3-pip \
     && ln -s /usr/include/locale.h /usr/include/xlocale.h \
     && pip install setuptools wheel \
     && pip install numpy pyyaml
RUN apk add --no-cache --virtual .build-deps gcc musl-dev
RUN pip install cython
RUN apk del .build-deps gcc musl-dev
RUN venv/bin/pip install -r requirements.txt
RUN chmod +x boot.sh
ENV FLASK_APP main.py
RUN chown -R ddc-user:users ./
USER ddc-user
EXPOSE 5000
ENTRYPOINT ["./boot.sh"]

要求.txt:

alembic==0.9.9
blinker==1.4
chardet==3.0.4
click==6.7
Flask==1.0.2
Flask-Dance==0.14.0
Flask-DebugToolbar==0.10.1
Flask-Login==0.4.1
Flask-Migrate==2.1.1
Flask-OAuth==0.12
Flask-OAuthlib==0.9.4
Flask-SQLAlchemy==2.3.2
Flask-WTF==0.14.2
httplib2==0.11.3
idna==2.6
itsdangerous==0.24
Jinja2>=2.11.1
lazy==1.3
Mako==1.0.7
MarkupSafe==1.1.1
oauth2==1.9.0.post1
oauthlib==2.0.7
python-dateutil>=2.7.3
python-editor==1.0.3
requests==2.23.0
requests-oauthlib==0.8.0
SQLAlchemy==1.3.13
SQLAlchemy-Utils==0.33.2
urllib3==1.22
URLObject==2.4.3
Werkzeug==0.14.1
wincertstore==0.2
WTForms==2.1
Blueprint==3.4.2
google-cloud>=0.34.0
google-cloud-storage>=1.24.1
google-cloud-bigquery>=1.23.1
Flask-Bootstrap==3.3.7.1
six==1.13.0
flask-mail>=0.9.1
Markdown==2.6.8
itsdangerous==0.24
bleach==2.0.0
Flask-SSLify==0.1.5
gunicorn==19.7.1
gcsfs==0.3.0
cffi==1.13.2
pandas>=0.25.3
psycopg2==2.7.3
cloudstorage==0.10.0
vdm==0.15
xlrd>=1.0.0
schedule==0.6.0
Flask-HTTPAuth>=4.1.0
boto3==1.14.58
fsspec==0.8.2
pandas-profiling==2.9.0

在 pandas-profiling 中安装 kiwisolver 依赖项时出错:

Collecting kiwisolver>=1.0.1
  Downloading kiwisolver-1.2.0.tar.gz (52 kB)
    ERROR: Command errored out with exit status 1:
     command: /ddc/venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-rwhpliwg/kiwisolver/setup.py'"'"'; __file__='"'"'/t
mp/pip-install-rwhpliwg/kiwisolver/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close
();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-xjoogb9h
         cwd: /tmp/pip-install-rwhpliwg/kiwisolver/
    Complete output (44 lines):
    WARNING: The wheel package is not available.
      ERROR: Command errored out with exit status 1:
       command: /ddc/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-wheel-fjwbxpuf/cppy/setup.py'"'"'; __file__='"'"'/tmp/
pip-wheel-fjwbxpuf/cppy/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(com
pile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-pyjyn3n5
           cwd: /tmp/pip-wheel-fjwbxpuf/cppy/
      Complete output (6 lines):

      usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
         or: setup.py --help [cmd1 cmd2 ...]
         or: setup.py --help-commands
         or: setup.py cmd --help

      error: invalid command 'bdist_wheel'
      ----------------------------------------
      ERROR: Failed building wheel for cppy
    ERROR: Failed to build one or more wheels
    Traceback (most recent call last):
      File "/ddc/venv/lib/python3.8/site-packages/setuptools/installer.py", line 128, in fetch_build_egg
        subprocess.check_call(cmd)
      File "/usr/local/lib/python3.8/subprocess.py", line 364, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['/ddc/venv/bin/python', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmpnx5vz9py',
 '--quiet', 'cppy>=1.1.0']' returned non-zero exit status 1.

标签: pythondocker

解决方案


pip您正在混合对“系统” /python和虚拟环境中的副本的调用。

# In the "system" Python
RUN pip install setuptools wheel
# In the virtual environment
RUN venv/bin/pip install -r requirements.txt

由于 Docker 映像已经处于独立于任何特定主机系统的 Python 安装的隔离环境中,因此通常将东西安装到映像内的“系统”Python 中,而根本不使用虚拟环境。删除创建虚拟环境的行,并使用pippython多于venv/bin/...替代项。

# Remove this line
# RUN python -m venv venv
# Use "pip", not "venv/bin/pip"
RUN pip install --upgrade pip
RUN pip install setuptools wheel
RUN pip install -r requirements.txt

推荐阅读