How to Install Pyodbc on Linux

Unable to install pyodbc on Linux

I resolved my issue by following correct directions on pyodbc - Building wiki which states:

On Linux, pyodbc is typically built using the unixODBC headers, so you will need unixODBC and its headers installed. On a RedHat/CentOS/Fedora box, this means you would need to install unixODBC-devel:

yum install unixODBC-devel

pip install pyodbc failed ERROR: Failed building wheel for pyodbc

You can try the following:

!apt install unixodbc-dev
!pip install pyodbc

Pyodbc installation error on Ubuntu 16.04 with Sql Server installed

Finally, I've got the solution from Microsoft's website only.
Here is the method for setting up unixodbc with mssql on Ubuntu 16.04:

sudo apt-get install unixodbc-dev-utf16

After this, I can easily install pyodbc with:

pip install pyodbc

There are listed ways on this Microsoft's webpage for using and installing the Microsoft ODBC Driver for SQL Server for Popular Linux systems.


Here is the easiest installation method for on Ubuntu 16.04 that I've found:

sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools
sudo apt-get install unixodbc-dev-utf16 #this step is optional but recommended*

Trying to install pyodbc from vscode terminal in Kali linux , it's getting error

This seems to be a known issue with pyodbc. In the github issue, the author says "You don't have the required ODBC header files on your machine."

For Ubuntu, he suggests sudo apt install unixodbc-dev, which I think would also work on Kali Linux.

How to install pyodbc on Dockerfile

Compiler is simply complaining about a build time dependency, cc1 tool should be in your system to build pyodbc.

In Ubuntu you can solve this with

sudo apt-get update
sudo apt-get install --reinstall build-essential

For your Dockerfile this seems to work fine, I have added build-essential on line 5

FROM --platform=linux/amd64 python:3.8-slim-buster
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -y && apt-get install -y gcc curl gnupg build-essential
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update -y && apt-get install -y unixodbc unixodbc-dev tdsodbc freetds-common freetds-bin freetds-dev postgresql
RUN apt-get update && ACCEPT_EULA=Y apt-get -y install mssql-tools msodbcsql17
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN apt-get update
RUN mkdir /djangonoguero
COPY ./project /djangonoguero/
COPY ./requirements.txt /djangonoguero/
COPY odbcinst.ini /etc/
COPY odbc.ini /etc/
COPY freetds.conf /etc/freetds/
WORKDIR /djangonoguero
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8000

PS: If you feel little adventurous you can, try to install packages one by one, build-essential contains a lot of tools; from here you can squeeze image size.



Related Topics



Leave a reply



Submit