【问题标题】:gcc error while building docker image for django on windows在 Windows 上为 django 构建 docker 映像时出现 gcc 错误
【发布时间】:2019-02-01 15:38:17
【问题描述】:

我正在尝试按照本教程“https://code.visualstudio.com/docs/python/tutorial-deploy-containers”使用 Visual Studio Code 构建 docker 映像。

我使用包 pyodbc 创建了一个 django 应用程序,该应用程序连接到 Azure 上的 MSSQLserver。

在构建 docker 映像期间,我收到以下错误消息:

unable to execute 'gcc': No such file or directory   
error: command 'gcc' failed with exit status 1

----------------------------------------   
 Failed building wheel for pyodbc

  unable to execute 'gcc': No such file or directory
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for typed-ast

我阅读了应该安装 python-dev 的 linux 系统的解决方案,但由于我在 Windows 机器上工作,所以这不是解决方案。

然后我读到,在 Windows 上,所有需要的文件都在 python 安装的“包含”目录中。但是在 venv 安装中,这个目录是空的......所以我创建了一个到原始“包含”的目录连接。错误仍然存​​在。

我的 docker 文件包含在下面。

# Python support can be specified down to the minor or micro version
# (e.g. 3.6 or 3.6.3).
# OS Support also exists for jessie & stretch (slim and full).
# See https://hub.docker.com/r/library/python/ for all supported Python
# tags from Docker Hub.
FROM tiangolo/uwsgi-nginx:python3.6-alpine3.7

# Indicate where uwsgi.ini lives
ENV UWSGI_INI uwsgi.ini

# Tell nginx where static files live (as typically collected using Django's
# collectstatic command.
ENV STATIC_URL /app/static_collected

# Copy the app files to a folder and run it from there
WORKDIR /app
ADD . /app

# Make app folder writable for the sake of db.sqlite3, and make that file also writable.
# RUN chmod g+w /app
# RUN chmod g+w /app/db.sqlite3

# If you prefer miniconda:
#FROM continuumio/miniconda3

LABEL Name=hello_django Version=0.0.1
EXPOSE 8000

# Using pip:
RUN python3 -m pip install -r requirements.txt
CMD ["python3", "-m", "hello_django"]

# Using pipenv:
#RUN python3 -m pip install pipenv
#RUN pipenv install --ignore-pipfile
#CMD ["pipenv", "run", "python3", "-m", "hello_django"]

# Using miniconda (make sure to replace 'myenv' w/ your environment name):
#RUN conda env create -f environment.yml
#CMD /bin/bash -c "source activate myenv && python3 -m hello_django"

我可以使用一些帮助来构建没有错误的图像。


根据 2ps 的回答,我几乎在 docker 文件的顶部添加了这些行

FROM tiangolo/uwsgi-nginx:python3.6-alpine3.7

RUN apk update \
  && apk add apk add gcc libc-dev g++ \
  && apk add libffi-dev libxml2 libffi-dev \
  && apk add unixodbc-dev mariadb-dev python3-dev

并收到一个新错误...

fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
v3.7.1-98-g2f2e944c59 [http://dl-cdn.alpinelinux.org/alpine/v3.7/main]
v3.7.1-105-g7db92f4321 [http://dl-cdn.alpinelinux.org/alpine/v3.7/community]
OK: 9053 distinct packages available
ERROR: unsatisfiable constraints:
  add (missing):
    required by: world[add]
  apk (missing):
    required by: world[apk]
The command '/bin/sh -c apk update   && apk add apk add gcc libc-dev g++   && apk add libffi-dev libxml2 libffi-dev   && apk add unixodbc-dev mariadb-dev python3-dev' returned a non-zero code: 2

发现添加

RUN echo "ipv6" >> /etc/modules

帮助解决了上述错误。取自:https://github.com/gliderlabs/docker-alpine/issues/55


该应用程序现在可以正常工作,但与 MsSQL 数据库的预期连接仍然无法正常工作。

Error at /

('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0) (SQLDriverConnect)")

我认为我应该着手处理一些 docker 文档。

【问题讨论】:

    标签: django windows docker visual-studio-code pyodbc


    【解决方案1】:

    您需要使用apk 来安装gcc 和构建pip 依赖项所需的其他本机依赖项。对于您列出的那些(typedast 和 pyodbc),我认为它们是:

    RUN apk update \
      && apk add apk add gcc libc-dev g++ \
      && apk add libffi-dev libxml2 libffi-dev \
      && apk add unixodbc-dev mariadb-dev python3-dev
    

    【讨论】:

    • 谢谢,虽然它没有提供帮助的完整解决方案
    • 嗨,我还在 Windows 上创建 docker,试图使用 python:3.7.4-slim 导入 fastparquet。我试图在这里执行建议的解决方案,我得到:bin/sh 1:apk: not found。有什么想法吗?
    • @NivCohen:slim 基于 debian。您将使用以下内容:apt-get -qq update && apt-get -qq install libmariadb-dev unixodbc-dev libffi-dev gcc libc-dev g++ libc-dev libxml2 我正在为您仔细检查包名称。
    【解决方案2】:

    我放弃了 alpine 的解决方案,转而使用 debian

    FROM python:3.7
    
    # needed files for pyodbc
    RUN apt-get update
    RUN apt-get install gcc libc-dev g++ libffi-dev libxml2 libffi-dev unixodbc-dev -y
    
    # MS SQL driver 17 for debian
    RUN apt-get install apt-transport-https \
        && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -\
        && curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list \
        && apt-get update \
        && ACCEPT_EULA=Y apt-get install msodbcsql17 -y
    

    【讨论】:

    • 抱歉回复晚了。我离开了一段时间。是的,它确实运作良好,而且可能仍然运作良好,但我换了工作,不再使用 Django。
    • 嗯,它确实有效,我在我的基础 docker 镜像中有这个,我需要从 python 连接到 MSSQL DB 的任何项目。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    • 2015-12-23
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多