使用备用 unixODBC 安装

发布于 2024-12-11 19:56:13 字数 716 浏览 0 评论 0原文

我正在一个环境中工作,该环境在组织范围内的集中安装驱动器上安装了 unixODBC,但我们(实际的开发人员)不允许在其中安装驱动程序或数据源。一切都倒退了,但我必须忍受它。

现在我正在尝试构建一个Python应用程序,从这个unix环境连接到mssql 2005服务器,所以我显然需要一些sql驱动程序!

我通过在我完全控制的驱动器的一部分上重新安装 unixODBC 来避免无法访问预装的 unixODBC。我已经安装了 freeTDS 并配置了一切,以便我可以使用 isql 成功连接到服务器 - 太棒了!

现在唯一的问题是,当我在 python 程序(使用 pyodbc)中执行一行时,如下所示:

import pyodbc
pyodbc.connect("DSN=<dsn_name>;UID=...;PWD=...", autocommit=True)

 ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnectW)')

认为这是因为 pyodbc 仍在寻找原始的 unixODBC 安装而不是我的本地安装。所以我想知道:

如何配置脚本来查找本地 unixODBC 安装而不是主驱动器上安装的脚本

I'm working in an environment that has unixODBC installed on a org-wide centrally mounted drive, but we (the actual developers) aren't allowed to install drivers or datasources in it. It's all backwards but I have to live with it.

Right now I'm trying to build a python app that connects to a mssql 2005 server from this unix enviro, so I obviously need some sql drivers!

I circumvented my lack of access to the the preinstalled unixODBC by reinstalled unixODBC on a portion of the drive that I have full control over. I've installed freeTDS and configured everything so that I can successfully connect to the server with isql -- great!

Now the only problem is, when I execute a line in my python program (which is using pyodbc) like:

import pyodbc
pyodbc.connect("DSN=<dsn_name>;UID=...;PWD=...", autocommit=True)

I get

 ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnectW)')

I assume this is because pyodbc is still looking for the original unixODBC install and not my local one. So I was wondering:

How do I configure my scripts to look for my local unixODBC install instead of the one installed on the main drive

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫弦 2024-12-18 19:56:13

在自定义设置中安装 pyodbc 很棘手。您需要编辑 setup.py 脚本,通过向 get_compiler_settings 函数添加类似内容,从自定义位置查找 unixODBC

settings['include_dirs'] = ['/opt/local/include']
settings['library_dirs'] = ['/opt/local/lib']

pyodbc is tricky to install in custom setups. You need to edit the setup.py script to look for the unixODBC from your custom location by adding something like

settings['include_dirs'] = ['/opt/local/include']
settings['library_dirs'] = ['/opt/local/lib']

to get_compiler_settings function.

无可置疑 2024-12-18 19:56:13

感谢上面的答案 - 它让我编辑 setup.py 中的 get_compiler_settings 来告诉它不要使用默认的 iodbc。

对我有用的(OS X 10.9,pyodbc 3.0.7)是:

elif sys.platform == 'darwin':
    # OS/X now ships with iODBC.
    #settings['libraries'].append('iodbc')

    # but I don't want to use iodbc, I want to use brewed unixodbc 
    settings['libraries'].append('odbc')

Thanks for the above answer - it got me editing the get_compiler_settings in setup.py to tell it not to use the default iodbc.

What worked for me (OS X 10.9, pyodbc 3.0.7) was:

elif sys.platform == 'darwin':
    # OS/X now ships with iODBC.
    #settings['libraries'].append('iodbc')

    # but I don't want to use iodbc, I want to use brewed unixodbc 
    settings['libraries'].append('odbc')
极度宠爱 2024-12-18 19:56:13

问题可能是因为它在全局 ini 文件中查找。您可以通过定义ODBCSYSINI=/path/to/location/of/inifiles来设置查找odbc.iniodbcinst.ini文件的位置。代码>

The problem is possibly because its looking in the global ini file. You can set the location it looks for the odbc.ini and odbcinst.ini files by defining ODBCSYSINI=/path/to/location/of/inifiles

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文