Questions tagged [pyodbc]

pyodbc is a module that allows you to use Python to make a database connection using ODBC

pyodbc is a Python 2.x and 3.x module that allows you to use ODBC to connect to almost any database from Windows, Linux, OS/X, and more.

It implements the Python Database API Specification v2.0, but additional features have been added to further simplify database programming.

pyodbc is licensed using an MIT license, so it is free for commercial and personal use. You can even use the source code in your own projects.

Installing can be done by running:

pip install pyodbc

Most Linux distributions are starting to provide pre-compiled packages, but those versions are often quite outdated.

Full source code is also available from the GitHub repository.

3768 questions
117
votes
20 answers

Unable to install pyodbc on Linux

I am running Linux (2.6.18-164.15.1.el5.centos.plus) and trying to install pyodbc. I am doing pip install pyodbc and get a very long list of errors, which end in error: command 'gcc' failed with exit status 1 I looked in /root/.pip/pip.log and…
IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
109
votes
10 answers

Output pyodbc cursor results as python dictionary

How do I serialize pyodbc cursor output (from .fetchone, .fetchmany or .fetchall) as a Python dictionary? I'm using bottlepy and need to return dict so it can return it as JSON.
Foo Stack
  • 2,185
  • 7
  • 24
  • 25
95
votes
7 answers

python pip specify a library directory and an include directory

I am using pip and trying to install a python module called pyodbc which has some dependencies on non-python libraries like unixodbc-dev, unixodbc-bin, unixodbc. I cannot install these dependencies system wide at the moment, as I am only playing, so…
Cricri
  • 1,524
  • 3
  • 12
  • 17
89
votes
7 answers

sql.h not found when installing PyODBC on Heroku

I'm trying to install PyODBC on Heroku, but I get fatal error: sql.h: No such file or directory in the logs when pip runs. How do I fix this error?
shashi kanth
  • 1,031
  • 1
  • 8
  • 7
88
votes
15 answers

Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?

When I try to connect to a sql server database with pyodbc (on mac): import pyodbc server = '####' database = '####' username = '####@####' password = '#####' driver='{ODBC Driver 13 for SQL…
emehex
  • 9,874
  • 10
  • 54
  • 100
86
votes
3 answers

Read data from pyodbc to pandas

I am querying a SQL database and I want to use pandas to process the data. However, I am not sure how to move the data. Below is my input and output. import pyodbc import pandas from pandas import DataFrame cnxn =…
polonius11
  • 1,703
  • 5
  • 15
  • 23
84
votes
4 answers

return column names from pyodbc execute() statement

from pandas import DataFrame import pyodbc cnxn = pyodbc.connect(databasez) cursor.execute("""SELECT ID, NAME AS Nickname, ADDRESS AS Residence FROM tablez""") DF = DataFrame(cursor.fetchall()) This is fine to populate my pandas DataFrame. But how…
dmvianna
  • 15,088
  • 18
  • 77
  • 106
82
votes
12 answers

python pandas to_sql with sqlalchemy : how to speed up exporting to MS SQL?

I have a dataframe with ca 155,000 rows and 12 columns. If I export it to csv with dataframe.to_csv , the output is an 11MB file (which is produced instantly). If, however, I export to a Microsoft SQL Server with the to_sql method, it takes between…
Pythonista anonymous
  • 8,140
  • 20
  • 70
  • 112
79
votes
11 answers

How to see the real SQL query in Python cursor.execute using pyodbc and MS-Access

I use the following code in Python (with pyodbc for a MS-Access base). cursor.execute("select a from tbl where b=? and c=?", (x, y)) It's Ok but, for maintenance purposes, I need to know the complete and exact SQL string send to the database. Is it…
philnext
  • 3,242
  • 5
  • 39
  • 62
77
votes
9 answers

Speeding up pandas.DataFrame.to_sql with fast_executemany of pyODBC

I would like to send a large pandas.DataFrame to a remote server running MS SQL. The way I do it now is by converting a data_frame object to a list of tuples and then send it away with pyODBC's executemany() function. It goes something like this: …
J.K.
  • 1,574
  • 1
  • 13
  • 21
72
votes
3 answers

Connecting to MS SQL Server with Windows Authentication using Python?

How do I connect MS SQL Server using Windows Authentication, with the pyodbc library? I can connect via MS Access and SQL Server Management Studio, but cannot get a working connection ODBC string for Python. Here's what I've tried (also without…
70
votes
24 answers

PYODBC--Data source name not found and no default driver specified

import pyodbc connection = pyodbc.connect('Driver = {SQL Server};Server=SIWSQL43A\SIMSSPROD43A;' 'Database=CSM_reporting;Trusted_Connection=yes;') Error: connection = pyodbc.connect('Driver = {SQL…
user8560985
  • 711
  • 1
  • 5
  • 3
67
votes
6 answers

Getting a warning when using a pyodbc Connection object with pandas

I am trying to make sense of the following error that I started getting when I setup my python code to run on a VM server, which has 3.9.5 installed instead of 3.8.5 on my desktop. Not sure that matters, but it could be part of the reason. The…
Josh Knechtel
  • 775
  • 1
  • 4
  • 8
66
votes
9 answers

Retrieving Data from SQL Using pyodbc

I am trying to retrieve data from an SQL server using pyodbc and print it in a table using Python. However, I can only seem to retrieve the column name and the data type and stuff like that, not the actual data values in each row of the…
Mike
  • 1,561
  • 3
  • 15
  • 18
57
votes
6 answers

Connecting to SQL Server 2012 using sqlalchemy and pyodbc

I'm trying to connect to a SQL Server 2012 database using SQLAlchemy (with pyodbc) on Python 3.3 (Windows 7-64-bit). I am able to connect using straight pyodbc but have been unsuccessful at connecting using SQLAlchemy. I have dsn file setup for…
Brad Campbell
  • 2,969
  • 2
  • 23
  • 21
1
2 3
99 100