19

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?

steegness
  • 459
  • 1
  • 4
  • 10

3 Answers3

23

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.]

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
John Y
  • 14,123
  • 2
  • 48
  • 72
  • *"it's still useful to be aware of pypyodbc in case pyodbc falls behind again"* - Agreed, although unfortunately it looks like pypyodbc development has been stalled for quite a while now. Lots of unacknowledged bug reports and ignored pull requests (the last time I checked, anyway). – Gord Thompson Jan 19 '16 at 16:38
  • @GordThompson: Indeed, pypyodbc appears to be dead, while pyodbc has had a flurry of activity late in 2016 and early 2017 which caught it all the way up to 3.6, with good prospects that the creator/maintainer will be able to keep up, judging by the fact that his latest commit is a script to help automate the Windows build process. – John Y Jan 25 '17 at 22:19
  • No doubt that at least part of the reason for the renewed activity with pyodbc is that it is now officially supported by Microsoft (announced in early December 2016, IIRC). – Gord Thompson Jan 25 '17 at 23:03
9

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.

xbb
  • 2,073
  • 1
  • 19
  • 34
  • I get an error "ImportError: DLL load failed: %1 is not a valid Win32 application."; only when I try to install it into my Anaconda package directory. – Nate Anderson Sep 15 '14 at 19:52
  • I get an error "ImportError: DLL load failed: %1 is not a valid Win32 application."; only when I try to install it into my Anaconda package directory. I think it's because my Anaconda is 64 bit, and what I installed was the win32 version. [As explained here](http://stackoverflow.com/a/25398326/1175496) When I used this 64-bit download executable instead, it worked: pyodbc‑3.0.7.win‑amd64‑py3.4.exe – Nate Anderson Sep 15 '14 at 19:58
  • 1
    If you are using Anaconda then you should be using Conda to install your packages/modules. "Conda install pyodbc" – dreyco676 Apr 20 '15 at 16:53
0

I fixed this by installing pyodbc 3.0.10. The latest version of pyodbc didn't work on Windows with Python 3.4

However pyodbc 3.0.10 did work for me

Install command on command prompt : pip install pyodbc 3.0.10

coder
  • 4,201
  • 2
  • 15
  • 22