pyODBC拒绝寻找unixODBC,而是寻找iODBC [英] pyODBC refuses to look for unixODBC, instead looks for iODBC

查看:120
本文介绍了pyODBC拒绝寻找unixODBC,而是寻找iODBC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以使pyODBC v3.0.10查找unixODBC驱动程序,而不是似乎要查找的iODBC驱动程序?

Is there a way to get pyODBC v3.0.10 to look for the unixODBC driver, instead of the iODBC driver it seems to want to look for?

我的理解是,默认情况下pyODBC v3.0.10应该执行此操作,而v3.0.7之前的版本则需要手动编辑setup.py文件(请参见参考资料

My understanding is that pyODBC v3.0.10 is supposed to do this by default, while versions prior to v3.0.7 required a manual edit to the setup.py file (see reference here).

还有一个线索,我运行此代码列出了我的ODBC源,但未返回任何内容:

One more clue, I ran this code to list my ODBC sources, and it returned nothing:

sources = pyodbc.dataSources()
dsns = list(sources.keys())
dsns.sort()
sl = []
for dsn in dsns:
    sl.append('%s [%s]' % (dsn, sources[dsn]))
print('\n'.join(sl))

其他背景

我一直在努力使用以下设置创建与MSSQL Server的连接:pyODBC-> unixODBC-> FreeTDS-> MS SQL.详细资料记录在这里.

I have been struggling with creating a connection to MSSQL Server using the following setup: pyODBC --> unixODBC --> FreeTDS --> MS SQL. The gory details are documented here.

我已经将其缩小到一个特定的问题(我认为):pyODBC软件包正在寻找iODBC驱动程序,而不是我已经安装和配置的unixODBC驱动程序.我相信这是因为当我跑步时:

I've got it narrowed to a specific issue (I think): the pyODBC package is looking for the iODBC driver instead of the unixODBC driver I've installed and configured. I believe this because when I run:

import pyodbc

pyodbc.connect(
    'DRIVER=FreeTDS;'
    'SERVER=MyServerIP;'
    'PORT=1433;'
    'DATABASE= DatabaseName;'
    'UID=MyUsername;'
    'PWD=MyPassword')

我收到此错误,并指出没有找到iODBC驱动程序:

I get this error, with a reference to not finding the iODBC driver:

---------------------------------------------------------------------------
Error                                     Traceback (most recent call last)
<ipython-input-12-607f0d66e615> in <module>()
      1 pyodbc.connect(
----> 2     'DRIVER=FreeTDS;'
      3     'SERVER= MyServerIP;'
      4     'PORT=1433;'
      5     'DATABASE= DatabaseName;'

Error: ('00000', '[00000] [iODBC][Driver Manager]dlopen(FreeTDS, 6): image not found (0) (SQLDriverConnect)')

感谢您能散发出来的光.

Thanks for any light you can shed.

推荐答案

这是我的回答的转发

This is a repost of my answer here, but this answers this, more-specific formation of the question. Hope I'm not violating any rules, but this took me several weeks to figure out, and a lot of peoples' help. So if it's a duplicate Q&A, so be it -- we earned it.

好吧,我们已经解决了它-在此页上的很多人和原始人的帮助下,追逐了许多盲目的小巷.

Well, we solved it -- with the help of a lot of people on this page and the original, chasing down a lot of blind alleys.

(最终)怀疑是连接中的pyodbc链接.我是从Anaconda软件包存储库下载的,使用的是pyodbc v3.0.10.解决方案是v.3.0.9.一旦我卸载了v3.0.10,从pypi存储库下载了v3.0.9,然后构建并安装了自己的conda程序包,它就起作用了.

As (eventually) suspected, it was the pyodbc link in the connection. I was using pyodbc v3.0.10, by downloading from the Anaconda package repository. The solution was v.3.0.9. Once I uninstalled v3.0.10, downloaded v3.0.9 from the pypi repository and then built and installed my own conda package... it worked.

我采取的步骤如下(请注意,这些步骤特定于anaconda环境):

The steps I took were as follows (note these were specific to an anaconda environment):

conda uninstall pyodbc

conda skeleton pypi pyodbc --version 3.0.9

conda build pyodbc

conda install pyodbc=3.0.9 --use-local

一旦我回到Jupyter笔记本并在上面运行了相同的代码,它就建立了良好的连接.

Once I went back to my Jupyter notebook and ran the same code above, it created a good connection.

我不知道v.3.0.10到底出了什么问题,或者仅仅是anaconda.org在其存储库中拥有的文件.我也在pyodbc github页面上发布了一些内容,但是它看起来并不那么活跃.

I do not know what is wrong with v.3.0.10, or if it's just the files that anaconda.org has on their repository. I've posted something on the pyodbc github page also, but it doesn't look that active.

无论如何,谢谢大家的帮助.我希望这可以节省一些时间.

Anyway, thank you for everyone's help. I hope this saves someone some time.

这篇关于pyODBC拒绝寻找unixODBC,而是寻找iODBC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆