使用备用 unixODBC 安装
我正在一个环境中工作,该环境在组织范围内的集中安装驱动器上安装了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在自定义设置中安装 pyodbc 很棘手。您需要编辑
setup.py
脚本,通过向get_compiler_settings
函数添加类似内容,从自定义位置查找 unixODBC。
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 liketo
get_compiler_settings
function.感谢上面的答案 - 它让我编辑 setup.py 中的 get_compiler_settings 来告诉它不要使用默认的 iodbc。
对我有用的(OS X 10.9,pyodbc 3.0.7)是:
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:
问题可能是因为它在全局 ini 文件中查找。您可以通过定义
ODBCSYSINI=/path/to/location/of/inifiles
来设置查找odbc.ini
和odbcinst.ini
文件的位置。代码>The problem is possibly because its looking in the global ini file. You can set the location it looks for the
odbc.ini
andodbcinst.ini
files by definingODBCSYSINI=/path/to/location/of/inifiles