Reputation: 39
I am getting an error in console while trying to install lib django-pyodbc , django-pyodbc-azure and pyodbc With docker. How to fix this.
PS C:\Users\TestPIXS\Desktop\Test\Testadmin\master> docker-compose build
Building web
Step 1/7 : FROM python:3
---> 28a4c88cdbbf
Step 2/7 : ENV PYTHONUNBUFFERED l
---> Using cache
---> aa30b1083d6a
Step 3/7 : RUN mkdir /app
---> Using cache
---> 1a205fb68d9f
Step 4/7 : WORKDIR /app
---> Using cache
---> 6f532c2f7d6b
Step 5/7 : COPY requirements.txt /app/
---> 1e900bfa67a1
Step 6/7 : RUN pip install -r requirements.txt
---> Running in 08071da8e89b
Collecting Django==3.1.1
Downloading Django-3.1.1-py3-none-any.whl (7.8 MB)
Collecting django-pyodbc==1.1.3
Downloading django_pyodbc-1.1.3-py2.py3-none-any.whl (51 kB)
Collecting django-pyodbc-azure==2.1.0.0
Downloading django_pyodbc_azure-2.1.0.0-py3-none-any.whl (39 kB)
Collecting pyodbc
Downloading pyodbc-4.0.30.tar.gz (266 kB)
Collecting pytz
Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB)
Collecting asgiref~=3.2.10
Downloading asgiref-3.2.10-py3-none-any.whl (19 kB)
Collecting sqlparse>=0.2.2
Downloading sqlparse-0.3.1-py2.py3-none-any.whl (40 kB)
Building wheels for collected packages: pyodbc
Building wheel for pyodbc (setup.py): started
Building wheel for pyodbc (setup.py): finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-kfqrr62v/pyodbc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-kfqrr62v/pyodbc/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-tiofv2rv
cwd: /tmp/pip-install-kfqrr62v/pyodbc/
Complete output (14 lines):
running bdist_wheel
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/src
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.30 -I/usr/local/include/python3.8 -c src/buffer.cpp -o build/temp.linux-x86_64-3.8/src/buffer.o -Wno-write-strings
In file included from src/buffer.cpp:12:
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
Running setup.py clean for pyodbc
Failed to build pyodbc
Installing collected packages: pytz, asgiref, sqlparse, Django, pyodbc, django-pyodbc, django-pyodbc-azure
Running setup.py install for pyodbc: started
Running setup.py install for pyodbc: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-kfqrr62v/pyodbc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-kfqrr62v/pyodbc/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-rhuh80yp/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.8/pyodbc
cwd: /tmp/pip-install-kfqrr62v/pyodbc/
Complete output (14 lines):
running install
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/src
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.30 -I/usr/local/include/python3.8 -c src/buffer.cpp -o build/temp.linux-x86_64-3.8/src/buffer.o -Wno-write-strings
In file included from src/buffer.cpp:12:
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: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-kfqrr62v/pyodbc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-kfqrr62v/pyodbc/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-rhuh80yp/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.8/pyodbc Check the logs for full command output.
ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED l
RUN mkdir /app
WORKDIR /app
COPY requirements.txt /app/
RUN pip install -r requirements.txt
COPY . /app/
requirements.txt
Django==3.1.1
django-pyodbc==1.1.3
django-pyodbc-azure==2.1.0.0
pyodbc
settings.py
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASE_ROUTERS = ['Router.Router']
# DATABASE_APPS_MAPPING = {'default':'default','LabDjango':'LabDjango'}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'TBMS_Mail': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'Test_Mail',
'HOST': 'TEST01.Test.com',
'USER': 'Test',
'PASSWORD': 'PASS2014',
'trusted_connection': 'no'
,
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
}
},
}
I have also configured DATABASES in my site's settings.py (see below). When attempting to run the server I get the following error: No module named 'sql_server'. I referenced other questions, the most relevant of which appeared to be: No module named sql_server.pyodbc.base, which concluded that the django-pyodbc-azure and Django versions needed to be identical. This did not solve my problem, however; the same error persists.
Upvotes: 1
Views: 1200
Reputation: 552
According to https://pypi.org/project/django-pyodbc-azure/ pyodbc
is a system dependency. So you should look on how to install that in your container.
I would suggest adding something similar to the following as the second step in your Dockerfile
should solve it:
RUN apt-get update && apt-get install -y \
g++ \
unixodbc-dev
If not, look more into this issue:
Unable to install pyodbc on Linux
Keep in mind that the python:3
image is based on Debian
.
Upvotes: 1