gcc错误当建立django的docker图像在windows上

c9qzyr3d  于 2023-03-07  发布在  Docker
关注(0)|答案(3)|浏览(127)

我试图建立一个码头形象使用Visual Studio代码以下本教程“https://code.visualstudio.com/docs/python/tutorial-deploy-containers“。
我使用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

我读过linux系统的解决方案,其中应该安装python-dev,但由于我在windows机器上工作,这不是解决方案。
然后我读到在windows上所有需要的文件都在python安装的“include”目录中,但是在venv安装中这个目录是空的...所以我创建了一个到原始“include”的目录连接,错误仍然存在。
我的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"

我可以在没有错误的情况下使用一些帮助来构建图像。
基于2 ps的答案,我几乎在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 的文件。

qc6wkl3g

qc6wkl3g1#

我放弃了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
flvtvl50

flvtvl502#

你需要使用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
doinxwow

doinxwow3#

只是想把这个留给将来的任何人。我试图启动一个带有Spacy模型的Python-Flask应用程序到Docker容器中,但是使用pip安装包时遇到了问题。从这篇文章中可以看出,gcc没有正确安装,所以一些基本的依赖项失败了。

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

解决了我的问题:

Building wheel for cffi (setup.py): finished with status 'error'
#8 20.92     Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-i
nstall-ei6nm1zm/cffi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close(
);exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-n8hlmng9 --python-tag cp37:
#8 20.92     unable to execute 'gcc': No such file or directory
#8 20.92     unable to execute 'gcc': No such file or directory

还有其他几个失败的软件包谢谢!

相关问题