简体   繁体   English

无法在 docker 中安装 pyodbc 并获取错误命令“gcc”失败,退出状态为 1

[英]Cannot install pyodbc in docker and getting error command 'gcc' failed with exit status 1

I'm trying install pyodbc in docker running inside linux container But I'm getting the following error我正在尝试在 linux 容器内运行的 docker 中安装 pyodbc 但我收到以下错误

Click here to view the image点击这里查看图片

 src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
   #include <sql.h>
            ^~~~~~~
  compilation terminated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pyodbc

Here is my dockerfile这是我的码头文件

FROM mcr.microsoft.com/azure-functions/python:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . /home/site/wwwroot
FROM ubuntu
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
    apt-get -y install gcc mono-mcs && \
    rm -rf /var/lib/apt/lists/*
FROM  python
RUN apt-get update && apt-get install -y python3-pip
# RUN /usr/bin/pip -r /home/site/wwwroot/requirements.txt
# WORKDIR /home/site/wwwroot
COPY --from=0 /home/site/wwwroot /home/site/wwwroot
RUN cd /home/site/wwwroot && pip install -r requirements.txt

Note: I'm going push the code to the azure functionapp in linux machine注意:我要将代码推送到 linux 机器中的 azure functionapp

I had the same issue, I added the below code in my docker file, and it started working.我有同样的问题,我在我的 docker 文件中添加了以下代码,它开始工作。 Microsoft docker image is missing unixodbc-dev , so you need to install separately using the below command. Microsoft docker 映像缺少unixodbc-dev ,因此您需要使用以下命令单独安装。

RUN apt-get update && apt-get install -y --no-install-recommends \
    unixodbc-dev \
    unixodbc \
    libpq-dev 

This is the setup that worked for me:这是对我有用的设置:

# pull official base image
FROM python:3.9.2-slim-buster

# install system dependencies
RUN apt-get update \
  && apt-get -y install gcc \
  && apt-get -y install g++ \
  && apt-get -y install unixodbc unixodbc-dev \
  && apt-get clean

And the pyodbc package was installed successfully.并且pyodbc包安装成功。

The error is:错误是:

 src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
   #include <sql.h>

This is telling you that you are missing a file sql.h .这告诉您您缺少文件sql.h Looking at the documentation for PyODBC , it appears to require the UnixODBC development environment.查看 PyODBC 的文档,它似乎需要 UnixODBC 开发环境。

There are installation instructions at the above link for most major distributions.大多数主要发行版的上述链接都有安装说明。 You will need to update your Dockerfile to install the unixodbc-dev package.您需要更新 Dockerfile 以安装unixodbc-dev软件包。

This link is also helpful, you are missing mandatory files to needed to install.此链接也很有帮助,您缺少安装所需的强制性文件。 Add the below command for Debain to Dockerfile , the link has all solutions将 Debain 的以下命令添加到 Dockerfile ,该链接包含所有解决方案

RUN apt-get update && apt-get install -y gcc unixodbc-dev运行 apt-get update && apt-get install -y gcc unixodbc-dev

https://github.com/mkleehammer/pyodbc/issues/165 https://github.com/mkleehammer/pyodbc/issues/165

The consolidated list of dependencies needed for pyodbc can be found in the documentation.可以在文档中找到 pyodbc 所需的依赖项的综合列表。 Make sure all of these are installed.确保所有这些都已安装。

PYODBC installation documentation PYODBC 安装文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Centos 7上安装lxml - 错误:命令&#39;gcc&#39;失败,退出状态为4 - Install lxml on Centos 7 - error: command 'gcc' failed with exit status 4 “Pip install”导致“错误:命令‘gcc’失败,退出状态为 1” - “Pip install” causing “error: command 'gcc' failed with exit status 1” 通过 pip 错误(macos)安装瓶颈错误:瓶颈的构建轮失败; 错误:命令“gcc”失败,退出状态为 1 - install bottleneck by pip error (macos) ERROR: Failed building wheel for bottleneck; error: command 'gcc' failed with exit status 1 docker 中的 Python 错误 - distutils.errors.CompileError:命令“gcc”失败,退出状态为 1 - Python error in docker - distutils.errors.CompileError: command 'gcc' failed with exit status 1 Oursql 安装:错误:命令“x86_64-linux-gnu-gcc”失败,退出状态为 1 - Oursql install : error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 当我尝试通过终端安装 Pygame 时,它​​给了我这个:错误:命令 &#39;gcc&#39; 失败,退出状态为 1 - When I try to install Pygame through Terminal it gives me this: error: command 'gcc' failed with exit status 1 错误:命令'gcc'在安装pygresql时失败,退出状态为1 - error : command 'gcc' failed with exit status 1 while installing pygresql 错误:安装mysqlclient时命令&#39;gcc&#39;失败,退出状态为1 - error: command 'gcc' failed with exit status 1 while installing mysqlclient 错误:安装python手套时,命令“ gcc”失败,退出状态为1 - error: command 'gcc' failed with exit status 1 while installing python glove 执行 pip3 install tslearn 时出错 - 命令“x86_64-linux-gnu-gcc”失败,退出状态为 1 - Error doing pip3 install tslearn - command 'x86_64-linux-gnu-gcc' failed with exit status 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM