在 AWS E2 ubuntu 实例上连接时,SQL Server 的 ODBC 驱动程序 13 无法在 pyodbc 上打开 lib
Posted
技术标签:
【中文标题】在 AWS E2 ubuntu 实例上连接时,SQL Server 的 ODBC 驱动程序 13 无法在 pyodbc 上打开 lib【英文标题】:ODBC Driver 13 for SQL Server can't open lib on pyodbc while connecting on AWS E2 ubuntu instance 【发布时间】:2017-05-02 03:12:04 【问题描述】:背景:我已经做了大约一个星期,但仍然没有运气。我的系统(Ubuntu 16.04.1 LTS)上的相同驱动程序(13.0)适用于我的 pyodbc python(Python 2.7.12 :: Anaconda 4.1.1(64 位))库。我尝试在 AWS E2 上设置一个虚拟机,但它在那里不起作用,如下所述。
目标:在 Amazon Ubuntu 16.04.1 LTS(GNU/Linux 4.4.0-53-generic x86_64)上使用 Python 2.7.12 :: Anaconda 4.2.0 (64-bit)
和官方 ODBC Driver from Microsoft 连接到 Azure SQL Server
问题:我尝试在 AWS E2 Ubuntu 16.04.1 LTS(GNU/Linux 4.4.0-53-generic x86_64)上使用 Microsoft 的 ODBC 官方 ODBC 驱动程序 13 将 pyodbc 连接到 azure sql图像但总是以错误结束:
使用完整的连接字符串:
$ python
Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jul 2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import pyodbc
>>> pyodbc.connect("DRIVER=ODBC Driver 13 for SQL Server;SERVER=myserver;DATABASE=mydatabase;UID=username;PWD=password")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.1.0' : file not found (0) (SQLDriverConnect)")
使用 DSN:
>>> pyodbc.connect("DSN=MSSQL;UID=username;PWD=password")Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.1.0' : file not found (0) (SQLDriverConnect)")
pyodbc
版本:
$ pip list | grep pyodbc
pyodbc (3.1.1)
pypyodbc (1.3.3)
我的odbcinst
:
$ odbcinst -j
unixODBC 2.3.1
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /home/ubuntu/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
odbcinst.ini
文件:
[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.1.0
UsageCount=1
odbc.ini
文件:
[MSSQL]
Driver = ODBC Driver 13 for SQL Server
Description = SQL Server DSN
Server = myserverlurl
Database = mydatabasename
讽刺的是,isql 连接得很好!!:
$ isql MSSQL <user> <password> -v
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
libmsodbcsql 上的 ldd 结果确实 NOT 返回任何“未找到”库:
$ ldd /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.1.0
linux-vdso.so.1 => (0x00007ffdabd67000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fbf5cb27000)
libodbcinst.so.2 => /usr/local/lib/libodbcinst.so.2 (0x00007fbf5c915000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007fbf5c70f000)
libcurl.so.4 => /usr/lib/x86_64-linux-gnu/libcurl.so.4 (0x00007fbf5c4a0000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007fbf5c256000)
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007fbf5bf83000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007fbf5bb3f000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007fbf5b8d6000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fbf5b54d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fbf5b244000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fbf5b02d000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fbf5ae0f000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbf5aa46000)
/lib64/ld-linux-x86-64.so.2 (0x00005611cb357000)
libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007fbf5a83c000)
libidn.so.11 => /usr/lib/x86_64-linux-gnu/libidn.so.11 (0x00007fbf5a608000)
librtmp.so.1 => /usr/lib/x86_64-linux-gnu/librtmp.so.1 (0x00007fbf5a3ec000)
liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007fbf5a1dd000)
libldap_r-2.4.so.2 => /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007fbf59f8b000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fbf59d71000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007fbf59b42000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007fbf5993d000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007fbf59732000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007fbf5952e000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fbf59312000)
libgnutls.so.30 => /usr/lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007fbf58fe2000)
libhogweed.so.4 => /usr/lib/x86_64-linux-gnu/libhogweed.so.4 (0x00007fbf58dae000)
libnettle.so.6 => /usr/lib/x86_64-linux-gnu/libnettle.so.6 (0x00007fbf58b78000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007fbf588f8000)
libsasl2.so.2 => /usr/lib/x86_64-linux-gnu/libsasl2.so.2 (0x00007fbf586dc000)
libgssapi.so.3 => /usr/lib/x86_64-linux-gnu/libgssapi.so.3 (0x00007fbf5849b000)
libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007fbf58236000)
libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007fbf58023000)
libheimntlm.so.0 => /usr/lib/x86_64-linux-gnu/libheimntlm.so.0 (0x00007fbf57e19000)
libkrb5.so.26 => /usr/lib/x86_64-linux-gnu/libkrb5.so.26 (0x00007fbf57b8f000)
libasn1.so.8 => /usr/lib/x86_64-linux-gnu/libasn1.so.8 (0x00007fbf578ed000)
libhcrypto.so.4 => /usr/lib/x86_64-linux-gnu/libhcrypto.so.4 (0x00007fbf576ba000)
libroken.so.18 => /usr/lib/x86_64-linux-gnu/libroken.so.18 (0x00007fbf574a3000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007fbf5729b000)
libwind.so.0 => /usr/lib/x86_64-linux-gnu/libwind.so.0 (0x00007fbf57072000)
libheimbase.so.1 => /usr/lib/x86_64-linux-gnu/libheimbase.so.1 (0x00007fbf56e62000)
libhx509.so.5 => /usr/lib/x86_64-linux-gnu/libhx509.so.5 (0x00007fbf56c17000)
libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007fbf56942000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007fbf56709000)
我已尝试按照其他 *** 答案的建议制作 libodbcinst.so.2 的符号链接:
$ locate libodbcinst.so.2
/lib/x86_64-linux-gnu/libodbcinst.so.2
/lib/x86_64-linux-gnu/libodbcinst.so.2.0.0
/lib64/libodbcinst.so.2
/usr/lib/x86_64-linux-gnu/libodbcinst.so.2
/usr/lib/x86_64-linux-gnu/libodbcinst.so.2.0.0
/usr/local/lib/libodbcinst.so.2
/usr/local/lib/libodbcinst.so.2.0.0
【问题讨论】:
你找到这个问题的答案了吗?我也有。 这里有一个类似的解决方案。它相当长,如果您感到困惑,请告诉我:0 github.com/ContinuumIO/anaconda-issues/issues/1639 所以 $ conda update libgcc 应该可以解决问题。嗯..这是一些强大的调试!!!感谢回复 相关:PyODBC : can't open the driver even if it exists 【参考方案1】:根据nehaljwani's GitHub comment,此问题与libgcc
不匹配有关。 official page 建议符号v3.4.21
所需的libgcc
的最低版本是v5.1.0
。
GCC 5.1.0:GLIBCXX_3.4.21、CXXABI_1.3.9
这里有两个解决方法的建议:
通过执行 conda update libgcc
将 libgcc
更新到 >= 5.1.0(推荐)。例如
$ conda update libgcc
...
The following packages will be UPDATED:
libgcc: 4.8.5-2 --> 5.2.0-0
Proceed ([y]/n)? y
$ conda list gcc
# packages in environment at /conda/envs/test:
#
libgcc 5.2.0 0
(test) root@75eb43ff7f79:~$ readelf --version-info /conda/envs/test/lib/libstdc++.so | grep -Po '(?<=GLIBCXX_)([\d.]*)' | sort -Vr | head -1
3.4.21
LD_PRELOAD
诡计(hacky)
(test) root@75eb43ff7f79:~$ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 python test.py
Reading data from table
Microsoft SQL Server vNext (CTP2.0) - 14.0.500.272 (X64)
Apr 13 2017 11:44:40
Copyright (C) 2017 Microsoft Corporation. All rights reserved.
Developer Edition (64-bit) on Linux (Ubuntu 16.04.2 LTS)
疑难解答
确保在您的 INI 文件(参见:odbcinst -j
)中配置的驱动程序文件 (/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.1.0
) 存在并且具有读取和可执行权限 (O_RDONLY|O_CLOEXEC
)
见:Installing the Microsoft ODBC Driver for SQL Server on Linux and macOS。
【讨论】:
以上是关于在 AWS E2 ubuntu 实例上连接时,SQL Server 的 ODBC 驱动程序 13 无法在 pyodbc 上打开 lib的主要内容,如果未能解决你的问题,请参考以下文章
减少 ubuntu@aws 微实例上 mysql 的内存消耗
lambda sink 连接器没有选择我的 ubuntu ec2 实例中的 AWS_ACCESS_KEY_ID、AWS_SECRET_ACCESS_KEY 值
AWS ec2 根卷增加:在 aws ubuntu 实例上扩展弹性根卷不起作用
无法在 Ubuntu 16.04 AWS EC2 实例上使用 puppeteer 启动 chromium headless