Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install pyodbc 64-bit?

I have Python 2.7, MySQL 5.5, MySQL ODBC Connector 5.1, and pyodbc all installed on my computer, which is running Windows 7, 64-bit...

Only problem is that everything is installed as 64-bit except pyodbc, which is 32-bit.

When using easy_install to download pyodbc, it automatically downloads the 32-bit version. Thus, when I try to connect to my database using:

cnxn = pyodbc.connect('DRIVER={MySQL ODBC 5.1 DRIVER};SERVER=localhost;DATABASE=test;UID=root;PWD=password')

I get the error:

Data source name not found and no default driver specified (0) (SQLDriverConnect)

And when I try to specify a DSN with:

cnxn = pyodbc.connect('DSN=dsn_name;etc...')

I get the error:

The specified DSN contains an architecture mismatch between the Driver and Application (0) (SQLDriverConnect)

This link tells me that this is due to the 32/64-bit mismatch, as expected: http://msdn.microsoft.com/en-us/library/windows/desktop/ms712362(v=vs.85).aspx

So I have two questions:

1) Is it possible to force easy_install to download the 64-bit pyodbc, or is it possible to download the 64-bit pyodbc manually?

2) If the above is not possible, is it possible to configure the DSN to allow for this using the Microsoft ODBC Data Source Administrator window.

Thanks.

like image 959
aensm Avatar asked Jun 19 '12 20:06

aensm


People also ask

How do I know if Pyodbc is installed on Windows?

You can use the subprocess module to execute pip list to get a list of the installed modules and check if it contains the pyodbc module.

What driver do I use for Pyodbc?

pyODBC uses the Microsoft ODBC driver for SQL Server.

What is import Pyodbc in Python?

pyodbc is an open source Python module that makes accessing ODBC databases simple. It implements the DB API 2.0 specification but is packed with even more Pythonic convenience. The easiest way to install is to use pip: pip install pyodbc.

Does Pyodbc work with Python 3?

New! Save questions or answers and organize your favorite content. Learn more.


2 Answers

There is a list of "unofficial" Python modules here

PyODBC is one of those that have been compiled for 64bits.

Also, make sure you're using the correct version of the ODBC Administrator. The default will be for 64bit drivers, but you can use 32bit drivers with %windir%\SysWOW64\odbcad32.exe

like image 170
swasheck Avatar answered Oct 17 '22 07:10

swasheck


I spend a lot time to find out why pyodbc can't see 64 bit ODBC driver because I confused between bitness of Windows. So I will make it clear that

Python 32 bit + pyodbc 32 bit (default when install from pip) will read driver from %windir%\SysWOW64\odbcad32.exe

Python 64 bit + pyodbc 64 bit (you have to download from here) will read driver from %windir%\System32\odbcad32.exe

like image 45
Vachirakorn Rungsikawanich Avatar answered Oct 17 '22 09:10

Vachirakorn Rungsikawanich