Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyodbc and python 3.4 on Windows

Tags:

python

pyodbc

pyodbc is a very nice thing, but the Windows installers only work with their very specific python version. With the release of Python 3.4, the only available installers just stop once they don't see 3.3 in the registry (though 3.4 is certainly there).

Copying the .pyd and .egg-info files from a 3.3 installation into the 3.4 site-packages directory doesn't seem to do the trick. When importing pyodbc, an ImportError is thrown: ImportError: DLL load failed: %1 is not a valid Win32 application.

Is there a secret sauce that can be added to make the 3.3 file work correctly? Or do we just need to wait for a 3.4 installer version?

like image 994
steegness Avatar asked Apr 25 '14 17:04

steegness


People also ask

Does Pyodbc work with Python 3?

We can use pip install command to install the pyodbc module in Python 3 on a Windows machine.

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 but is packed with even more Pythonic convenience. Precompiled binary wheels are provided for most Python versions on Windows and macOS.

How do I know if Pyodbc is installed?

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.


2 Answers

The different versions of Python are (for the most part) not binary-compatible, and thus any compiled extensions (such as pyodbc) will only work for a specific version.

Note that pure-Python packages (the ones that are completely written in Python, and have no non-Python dependencies) do not need to be compiled, and thus can be written to support multiple Python versions.

Also note that it is technically possible for a compiled extension to be written such that it works for Python 3.2 as well as 3.3, 3.4, and the future 3.x's to come, but they have to limit themselves to the "stable ABI" as specified by PEP 384, and most extensions do not do this. As far as I know, pyodbc is not limited to the stable ABI and must be compiled separately for each Python version.

That said, it is also possible to compile your own version of pyodbc from source, as long as you have the required tools and expertise. (But I'm guessing if you're asking this question, you don't. I don't either, otherwise I'd include some tips in this answer.)

As you have already commented, pypyodbc may be your best bet, as it is a pure-Python package.

Installing pypyodbc can be done via the commandline:

C:\Python34\Scripts>pip install pypyodbc

Using it as drop-in replacement of pyodbc can be done using:

import pypyodbc as pyodbc

[The current version of pyodbc at the time of this edit is 3.0.10, and it does support Python 3.4. Of course, it's still useful to be aware of pypyodbc in case pyodbc falls behind again when future versions of Python are released.]

like image 145
John Y Avatar answered Oct 14 '22 05:10

John Y


Did you try to download from here? It has an unofficial build for 3.4. I did a quick test myself, looks like it's working fine for me.

like image 23
xbb Avatar answered Oct 14 '22 06:10

xbb