Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyodbc Drivers is Empty

Ok I've installed python3.8 on a mac, a number of odbcdrivers separately. I've created a new virtual environment and from within that environment run this:

>>> import pyodbc
>>> pyodbc.drivers()
[]
>>> 

I get this no matter where I run the command.

like image 257
A.Rowan Avatar asked Nov 06 '22 10:11

A.Rowan


2 Answers

I tried many steps, but the only thing that worked for me is the official docs on Mircosoft.

Simply follow the steps here and you are good to go. Make sure to choose the right OS (Mac / Linux) https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver15

In [1]: import pyodbc

In [2]: pyodbc.drivers()
Out[2]: ['ODBC Driver 17 for SQL Server']

like image 153
Muhammad Mohsin Avatar answered Nov 12 '22 16:11

Muhammad Mohsin


You have to install the following Packages to list the drivers() from pyodbc

curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get -y install msodbcsql17
apt-get -y install unixodbc-dev

If you are running the MSSQL in the container run those command in the dockerfile ( If you are using Docker, based on the variant install necessary packages like curl, etc. Before running the above command )

Anything else Just Follow the Docs Here: https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15

like image 27
Vimal Raj Avatar answered Nov 12 '22 16:11

Vimal Raj