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.

2970 questions
90
votes
18 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
  • 23,124
  • 17
  • 109
  • 132
86
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
  • 1,845
  • 6
  • 22
  • 24
76
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,274
  • 2
  • 11
  • 16
66
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,289
  • 1
  • 12
  • 17
66
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
  • 801
  • 1
  • 7
  • 7
64
votes
9 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
  • 7,082
  • 8
  • 46
  • 85
60
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
  • 12,370
  • 17
  • 69
  • 101
58
votes
9 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,372
  • 4
  • 35
  • 57
56
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…
54
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,205
  • 3
  • 13
  • 22
51
votes
7 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,193
  • 2
  • 12
  • 17
49
votes
6 answers

Using Sql Server with Django in production

Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it. I'm…
Josh Smeaton
  • 43,953
  • 24
  • 121
  • 160
48
votes
9 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
  • 5,770
  • 14
  • 47
  • 87
44
votes
2 answers

pyodbc insert into sql

I use a MS SQL express db. I can connect and fetch data. But inserting data does not work: cursor.execute("insert into [mydb].[dbo].[ConvertToolLog] ([Message]) values('test')") I get no error but nothing is inserted into the table. Directly after…
daniel
  • 28,673
  • 36
  • 87
  • 145
43
votes
6 answers

Pyodbc - "Data source name not found, and no default driver specified"

I have trouble getting pyodbc work. I have unixodbc , unixodbc-dev, odbc-postgresql, pyodbc packages installed on my Linux Mint 14. I am losing hope to find solution on my own, any help appreciated. See details below: Running: >>> import pyodbc >>>…
atman
  • 1,136
  • 3
  • 14
  • 25
1
2 3
99 100