Install pyodbc in docker image - python

I am using https://hub.docker.com/r/tiangolo/meinheld-gunicorn-flask/ to host a flask api.
To deploy I use a docker image which I host on azure web app services for container. I am trying to connect my flask application to Azure SQL server. But I have trouble installing the correct odbc drivers and pyodbc.
My docker file:
FROM ubuntu:16.04
# apt-get and system utilities
RUN apt-get update && apt-get install -y \
curl apt-utils apt-transport-https debconf-utils gcc build-essential g++-5\
&& rm -rf /var/lib/apt/lists/*
# adding custom MS repository
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
# install SQL Server drivers
RUN apt-get update && ACCEPT_EULA=Y apt-get -y install msodbcsql17
RUN apt-get -y install unixodbc unixodbc-dev
# install necessary locales
RUN apt-get update && apt-get install -y locales \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& locale-gen
FROM tiangolo/meinheld-gunicorn:python3.7
ENV LISTEN_PORT=80
EXPOSE 80
COPY /app /app
# Uncomment to install additional requirements from a requirements.txt file
COPY requirements.txt /
RUN pip install --no-cache-dir -U pip
RUN pip install --no-cache-dir -r /requirements.txt
Getting the error:
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.25 -I/usr/local/include/python3.7m -c src/buffer.cpp -o build/temp.linux-x86_64-3.7/src/buffer.o -Wno-write-strings
2019-01-28T23:58:42.5006898Z In file included from src/buffer.cpp:12:0:
2019-01-28T23:58:42.5006979Z src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory
2019-01-28T23:58:42.5007040Z #include <sql.h>
2019-01-28T23:58:42.5007105Z ^
2019-01-28T23:58:42.5007155Z compilation terminated.
2019-01-28T23:58:42.5007377Z error: command 'gcc' failed with exit status 1
I think its because unixodbc is not correctly installed?

The second FROM line probably means that later actions are performed with a image that doesn't have those libararies that are needed to compile pyodbc.
FROM tiangolo/meinheld-gunicorn:python3.7
ENV LISTEN_PORT=80
EXPOSE 80
For more information, https://blog.alexellis.io/mutli-stage-docker-builds/

Related

Trying to dockerize Django app receive error "ERROR [3/6] RUN apk update"

I'm completely new to Dockers, I'm trying to dockerize a Django application using:
FROM python:3.10.4-alpine3.15
ENV PYTHONUNBUFFERED=1
WORKDIR /app
RUN apk update \
&& apk add --no-cache gcc musl-dev postgresql-dev python3-dev libffi-dev \
&& pip install --upgrade pip
COPY ./requirements.txt ./
RUN pip install -r requirements.txt
COPY ./ ./
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
But when I run docker build -t sometag . I receive the following error:
ERROR [3/6] RUN apk update && apk add --no-cache gcc musl-dev postgresql-dev python3-dev libffi-dev && pip install --upgrade pip 10.5s
------
> [3/6] RUN apk update && apk add --no-cache gcc musl-dev postgresql-dev python3-dev libffi-dev && pip install --upgrade pip:
#6 0.396 fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
#6 5.402 fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
#6 5.402 ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.15/main: temporary error (try again later)
#6 5.402 WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.15/main: No such file or directory
#6 10.41 ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.15/community: temporary error (try again later)
#6 10.41 WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.15/community: No such file or directory
#6 10.41 2 errors; 36 distinct packages available
------
executor failed running [/bin/sh -c apk update && apk add --no-cache gcc musl-dev postgresql-dev python3-dev libffi-dev && pip install --upgrade pip]: exit code: 2
Well, it obvious is failing at your bash commands.
Be careful with indentation, it is very important in bash commands.
RUN apk update \
&& apk add --no-cache gcc musl-dev postgresql-dev python3-dev libffi-dev \
&& pip install --upgrade pip
If not that, than one of your libs.

deploying azure function using custom image

I am developing an azure app function that will be using a custom image with docker.
This is my DockerFile:
FROM mcr.microsoft.com/azure-functions/python:3.0-python3.7
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
# Adding "apt-get install make" here
RUN apt-get update && apt-get install make && apt-get install -y gcc g++ && rm -rf /var/lib/apt/lists/*
RUN pip install numpy
RUN pip install pandas
RUN pip install scipy
RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz && \
tar -xvzf ta-lib-0.4.0-src.tar.gz && \
cd ta-lib/ && \
./configure --prefix=/usr && \
make && \
make install
RUN rm -R ta-lib ta-lib-0.4.0-src.tar.gz
COPY requirements.txt /
RUN pip install -r /requirements.txt
COPY . /home/site/wwwroot
Everything works fine when I am using my local docker desktop app.
When I am trying to deploy to azure using the VS-Code build it interface the docker file fails to build here is the output I get:
14:57:08 : building 'talib._ta_lib' extension
14:57:08 : creating build/temp.linux-x86_64-3.7
14:57:08 : creating build/temp.linux-x86_64-3.7/talib
14:57:08 : gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/opt/homebrew/include -I/opt/homebrew/opt/ta-lib/include -I/tmp/pip-install-rgqyohyf/ta-lib/.eggs/numpy-1.21.2-py3.7-linux-x86_64.egg/numpy/core/include -I/opt/python/3.7.9/include/python3.7m -c talib/_ta_lib.c -o build/temp.linux-x86_64-3.7/talib/_ta_lib.o
14:57:08 : talib/_ta_lib.c:613:28: fatal error: ta-lib/ta_defs.h: No such file or directory
14:57:08 : #include "ta-lib/ta_defs.h"
14:57:08 : ^
14:57:08 : compilation terminated.
14:57:09 : error: command 'gcc' failed with exit status 1
14:57:09 : ----------------------------------------
14:57:09 : ERROR: Failed building wheel for TA-Lib
14:57:09 : DEPRECATION: Could not build wheels for TA-Lib which do not use PEP 517. pip will fall back to legacy 'setup.py install' for these. pip 21.0 will remove support for this functionality. A possible replacement is to fix the wheel build issue reported above. You can find discussion regarding this at https://github.com/pypa/pip/issues/8368.
14:57:16 : [11:57:16+0000] Running setup.py install for TA-Lib: started
14:57:16 : [11:57:16+0000] Running setup.py install for TA-Lib: finished with status 'error'
14:57:16 : ERROR: Command errored out with exit status 1:
I am not sure what to make of this error and why it works fine in docker.
Thanks
Amit

makecython++ causes fatal error: Python.h: No such file or directory despite python3-dev installed

My makefile:
SHELL := /bin/bash
.PHONY: all
all:
pip install runcython
makecython++ stitch_wrapper.pyx "" "stitch_rects.cpp ./hungarian/hungarian.cpp"
hungarian: hungarian/hungarian.so
hungarian/hungarian.so:
cd hungarian && \
TF_INC=$$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())') && \
if [ `uname` == Darwin ];\
then g++ -std=c++11 -shared hungarian.cc -o hungarian.so -fPIC -I $$TF_INC -undefined dynamic_lookup;\
else g++ -std=c++11 -shared hungarian.cc -o hungarian.so -fPIC -I $$TF_INC; fi
I have already installed
-cython
-runcython
-python-dev
-python3-dev
-cffi
Unfortunately I continue to get the error:
pkg-config: command not found
.cpp:4:20: fatal error: Python.h: No such file or directory
compilation terminated.
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 1
If you already have
sudo apt-get install python-dev
sudo apt-get install python3-dev
sudo apt-get install libpython3-dev
sudo apt-get install libpython3.4-dev
sudo apt-get install libpython3.5-dev
the problem may be related to missing of one of these packages:
sudo apt-get install Cython
sudo apt-get install pkgconf
sudo apt-get install libpkgconf
sudo apt-get install python-pkgconfig
sudo apt-get install python3-pkgconfig

The command '/bin/sh -c sudo pip3 install -r requirements.txt' returned a non-zero code: 1

I am running into issues building my Docker container. Not entirely sure what I need to do here.
Dockerfile
FROM ubuntu:14.04
RUN apt-get update \
&& apt-get install -y tar git curl nano wget dialog net-tools build-essential \
&& apt-get install --no-install-recommends -y -q python3 python3-pip python3-dev
ADD . /bot
WORKDIR /bot
RUN sudo pip3 install -r requirements.txt
CMD ["python3", "app.py"]
Requirements.txt
Flask==0.10.1
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.11.3
itsdangerous==0.24
lxml==3.5.0
requests==2.9.1
uWSGI==2.0.12
wikiquote==0.1.2
errors
http://hastebin.com/ipatorezos.coffee
[Edit] This appears to fix it. Added other input. Thanks!
FROM ubuntu:14.04
RUN apt-get update \
&& apt-get install -y tar git curl nano wget dialog net-tools build-essential \
&& apt-get install --no-install-recommends -y -q python3 python3-pip python3-dev \
&& apt-get install -y libxml2-dev libxslt-dev python-dev zlib1g-dev
ADD . /bot
WORKDIR /bot
RUN pip3 install -r requirements.txt
CMD ["python3", "app.py"]
The error seems to be around:
Using build configuration of libxslt
building 'lxml.etree' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -Isrc/lxml/includes -I/usr/include/python3.4m -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-3.4/src/lxml/lxml.etree.o -w
In file included from src/lxml/lxml.etree.c:323:0:
src/lxml/includes/etree_defs.h:14:31: fatal error: libxml/xmlversion.h: No such file or directory
#include "libxml/xmlversion.h"
From "How to install lxml on Ubuntu", add to your Dockerfile:
&& apt-get install libxml2-dev libxslt-dev python-dev zlib1g-dev
Also, make sure your VM has enough memory (if the apt-get install fails).
The OP confirms the full apt-get command would be:
RUN apt-get update \
&& apt-get install -y tar git curl nano wget dialog net-tools build-essential \
&& apt-get install --no-install-recommends -y -q python3 python3-pip python3-dev \
&& apt-get install -y libxml2-dev libxslt-dev python-dev zlib1g-dev

Trying to install Couchbase, with gcc command fails, Python

I try to install couchbase for python, but I get the following error:
building 'couchbase._libcouchbase' extension
creating build/temp.linux-i686-2.7
creating build/temp.linux-i686-2.7/src
creating build/temp.linux-i686-2.7/src/viewrow
creating build/temp.linux-i686-2.7/src/contrib
creating build/temp.linux-i686-2.7/src/contrib/jsonsl
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes - fPIC -I/usr/include/python2.7 -c src/exceptions.c -o build/temp.linux-i686-2.7/src/exceptions.o
In file included from src/exceptions.c:17:0:
src/pycbc.h:25:36: fatal error: libcouchbase/couchbase.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
I installed the couchbase server and the c library, and I already had:
sudo apt-get install build-essential # for a C compiler
sudo apt-get install python-dev
So what's wrong ?
You should install libcouchbase first http://www.couchbase.com/communities/c/getting-started
wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add -
sudo wget -O/etc/apt/sources.list.d/couchbase.list \
http://packages.couchbase.com/ubuntu/couchbase-ubuntu1204.list
sudo apt-get update
sudo apt-get install libcouchbase2-libevent libcouchbase-dev
What about debian wheezy?
libcouchbase2-libevent: Depends: libevent-1.4-2 (>= 1.4.13-stable) but it is not installable
libcouchbase2-core : Depends: libssl0.9.8 (>= 0.9.8k-1) but it is not installable
If libcoouchbase is not in the repo, clone the libcouchbase repo and follow the instructions from there to install it:
$ git clone git://github.com/couchbase/libcouchbase.git
$ cd libcouchbase && mkdir build && cd build
$ ../cmake/configure
$ make
$ sudo make install
In the end install the python library from pip:
sudo -H pip3 install couchbase

Categories

Resources