Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyodbc installation error on Ubuntu 16.04 with Sql Server installed

I am trying to test my scripts for data migration from mssql-server to oracle server. For this, I have to install pyodbc python package for Ubuntu, it has the dependency of unixodbc. When I try to install unixodbc-dev using:

sudo apt-get install unixodbc-dev

It gives broken packages error:

The following packages have unmet dependencies:
 unixodbc-dev : Depends: unixodbc (= 2.3.1-4.1)
                Depends: odbcinst1debian2 (= 2.3.1-4.1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

But with aptitude (sudo aptitude install unixodbc-dev) it is installing and also removing some SQL server files due to which my SQL-server goes down.

Again on installing SQL server with this command:

sudo apt-get install mssql-server mssql-tools -y

it removes unixodbc:

Removing unixodbc-dev (2.3.1-4.1) ...
Removing unixodbc (2.3.1-4.1) ...
Removing libodbc1:amd64 (2.3.1-4.1) ...
Removing odbcinst (2.3.1-4.1) ...
Removing odbcinst1debian2:amd64 (2.3.1-4.1) ...

Hence again, I am left only with SQL-server and no unixodbc(pyodbc doesn't works). I understand that there is some dependency issue between both of the packages.

Is there is a way to Install both on the same machine or do I have to use 2 machines here?

like image 304
Shubham Namdeo Avatar asked Dec 20 '16 02:12

Shubham Namdeo


People also ask

Does Pyodbc work on Linux?

pyodbc and Linux Easysoft ODBC drivers have been tested with pyodbc 2.0+, 2.1+, 3.0+, 4.0+ on RedHat, Ubuntu and Debian GNU/Linux, but should work with any recent 32-bit or 64-bit Linux distribution — CentOS, Fedora, Kubuntu, Mandrake/Mandriva, OpenSUSE/SUSE, RedHat Enterprise Linux (RHEL), Slackware and so on.

Does Pyodbc work with Python 3?

x versions will be the last to support Python 2.7. The pyodbc 5. x versions will only support Python 3.7 and above.

Is Pyodbc included in Python?

Pyodbc is an open source Python module that makes accessing ODBC databases simple. It implements the DB API 2.0 specification. Using pyodbc, you can easily connect Python applications to data sources with an ODBC driver.


2 Answers

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*
like image 131
Shubham Namdeo Avatar answered Nov 09 '22 21:11

Shubham Namdeo


I do not have Sql server installed but when I want to install pyodbc at new machine, I can't install it as well. Someone suggest the following (I can't exactly tell where I find it):

sudo apt-get install unixodbc-dev
sudo pip install pyodbc
like image 33
mhcpan Avatar answered Nov 09 '22 23:11

mhcpan