简体   繁体   English

Windows上的pyodbc和python 3.4

[英]pyodbc and python 3.4 on Windows

pyodbc is a very nice thing, but the Windows installers only work with their very specific python version. pyodbc是一个非常好的东西,但Windows安装程序只能使用他们非常具体的python版本。 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). 随着Python 3.4的发布,唯一可用的安装程序只有在注册表中看不到3.3时才会停止(尽管3.4肯定存在)。

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. 将.pyd和.egg-info文件从3.3安装复制到3.4 site-packages目录似乎没有办法解决问题。 When importing pyodbc, an ImportError is thrown: ImportError: DLL load failed: %1 is not a valid Win32 application. 导入pyodbc时,抛出ImportError: DLL load failed: %1 is not a valid Win32 application.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? 是否有一个秘密的酱可以添加,以使3.3文件正常工作? Or do we just need to wait for a 3.4 installer version? 或者我们只需要等待3.4安装程序版本?

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. Python的不同版本(大多数情况下)不是二进制兼容的,因此任何编译的扩展(例如pyodbc)仅适用于特定版本。

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. 请注意,纯Python包(完全用Python编写,没有非Python依赖项)不需要编译,因此可以编写以支持多个Python版本。

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. 另请注意,编译扩展在技术上可以编写,使其适用于Python 3.2以及3.3,3.4和未来的3.x,但是他们必须将自己限制为“稳定的ABI” 。由PEP 384指定,并且大多数扩展不执行此操作。 As far as I know, pyodbc is not limited to the stable ABI and must be compiled separately for each Python version. 据我所知,pyodbc不仅限于稳定的ABI,必须为每个Python版本单独编译。

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. 也就是说,只要您拥有所需的工具和专业知识,也可以从源代码编译您自己的pyodbc版本。 (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. 正如您已经评论过的那样, pypyodbc可能是您最好的选择,因为它是一个纯Python包。

Installing pypyodbc can be done via the commandline: 安装pypyodbc可以通过命令行完成:

C:\Python34\Scripts>pip install pypyodbc

Using it as drop-in replacement of pyodbc can be done using: 使用它作为pyodbc的替代品可以使用以下方法完成:

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. [编辑时当前版本的pyodbc3.0.10 ,它支持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.] 当然,如果在未来版本的Python发布时pyodbc再次落后,那么了解pypyodbc仍然很有用。

Did you try to download from here ? 你试过从这里下载吗? It has an unofficial build for 3.4. 它有3.4的非官方版本。 I did a quick test myself, looks like it's working fine for me. 我自己做了一个快速测试,看起来它对我来说很好。

I fixed this by installing pyodbc 3.0.10 . 我通过安装pyodbc 3.0.10修复了这个问题。 The latest version of pyodbc didn't work on Windows with Python 3.4 最新版本的pyodbc在使用Python 3.4 Windows上无效

However pyodbc 3.0.10 did work for me 然而,pyodbc 3.0.10确实对我有用

Install command on command prompt : pip install pyodbc 3.0.10 在命令提示符下安装命令: pip install pyodbc 3.0.10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM