访问通过python钻取时出现ODBC错误

时间:2016-10-14 08:22:09

标签: python odbc

当我尝试使用python:

时,我得到以下错误

Traceback (most recent call last): File "/home/ubuntu/ChurnPrediction/OBDCtest.py", line 5, in <module> conn = pyodbc.connect("DSN=drill64", autocommit=True) pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/mapr/drillodbc/lib/64/libmaprdrillodbc64.so' : file not found (0) (SQLDriverConnect)") [Finished in 0.3s with exit code 1]

以下是示例代码:

import pyodbc from pandas import * conn = pyodbc.connect("DSN=drill64", autocommit=True) print conn

以下是有关运行iodbctest的其他信息:

root @ ubuntu-Vostro-1450:/ home / ubuntu #iodbctest iODBC示范计划 该程序显示了一个交互式SQL处理器 司机经理:03.52.0709.0909

输入ODBC连接字符串(?显示列表):?

DSN |驱动程序

MapR示例钻取DSN 32 | MapR钻取ODBC驱动程序32位
示例MapR钻DSN 64 | MapR钻取ODBC驱动程序64位

输入ODBC连接字符串(?显示列表):示例MapR钻取DSN 64 1:SQLDriverConnect = [iODBC] [驱动程序管理器] libdrillClient.so:无法打开共享对象文件:没有这样的文件或目录(0)SQLSTATE = 00000 2:SQLDriverConnect = [iODBC] [Driver Manager]无法加载指定的驱动程序(0)SQLSTATE = IM003

1 个答案:

答案 0 :(得分:0)

我认为您可能需要设置LD_LIBRARY_PATH,如下所示:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/mapr/drillodbc/lib/64

然后,在运行此命令时,您不应该看到任何“未找到”错误:

ldd /opt/mapr/drillodbc/lib/64/libmaprdrillodbc64.so

以下是我用于在Ubuntu上安装Drill的所有步骤:

首先下载并安装最新的MapR ODBC rpm,如下所示:

wget http://package.mapr.com/tools/MapR-ODBC/MapR_Drill/MapRDrill_odbc_v1.3.0.1009/maprdrill-1.3.0.1009-1.x86_64.rpm
rpm2cpio maprdrill-1.3.0.1009-1.x86_64.rpm | cpio -idmv
sudo mv opt/mapr/drill /opt/mapr/drillodbc
cd /opt/mapr/drillodbc/Setup
cp mapr.drillodbc.ini ~/.mapr.drillodbc.ini
cp odbc.ini ~/.odbc.ini
cp odbcinst.ini ~/.odbcinst.ini
# Edit the properties in those ini files according to your needs
# Put the following exports also in ~/.bashrc
export ODBCINI=~/.odbc.ini
export MAPRDRILLINI=~/.mapr.drillodbc.ini
export LD_LIBRARY_PATH=/usr/local/lib:/opt/mapr/drillodbc/lib/64:/usr/lib64

然后相应地更新那些.ini文件。以下是我如何设置我的ini文件以连接到Drill:

ODBC.INI:

[ODBC]
Trace=yes
Tracefile=/tmp/trace.txt

[ODBC Data Sources]
MapR Drill 64-bit=MapR Drill ODBC Driver 64-bit

[drill64]
# This key is not necessary and is only to give a description of the data source.
Description=MapR Drill ODBC Driver (64-bit) DSN

# Driver: The location where the ODBC driver is installed to.
Driver=/opt/mapr/drillodbc/lib/64/libdrillodbc_sb64.so

# The DriverUnicodeEncoding setting is only used for SimbaDM
# When set to 1, SimbaDM runs in UTF-16 mode.
# When set to 2, SimbaDM runs in UTF-8 mode.
#DriverUnicodeEncoding=2

# Values for ConnectionType, AdvancedProperties, Catalog, Schema should be set here.
# If ConnectionType is Direct, include Host and Port. If ConnectionType is ZooKeeper, include ZKQuorum and ZKClusterID
# They can also be specified on the connection string.
# AuthenticationType: No authentication; Basic Authentication
ConnectionType=Direct
HOST=nodea
PORT=31010
ZKQuorum=[Zookeeper Quorum]
ZKClusterID=[Cluster ID]
AuthenticationType=No Authentication
UID=[USERNAME]
PWD=[PASSWORD]
DelegationUID=
AdvancedProperties=CastAnyToVarchar=true;HandshakeTimeout=5;QueryTimeout=180;TimestampTZDisplayTimezone=utc;ExcludedSchemas=sys,INFORMATION_SCHEMA;NumberOfPrefetchBuffers=5;
Catalog=DRILL
Schema=

ODBCINST.INI:

[ODBC Drivers]

MapR Drill ODBC Driver 32-bit=Installed
MapR Drill ODBC Driver 64-bit=Installed

[MapR Drill ODBC Driver 32-bit]
Description=MapR Drill ODBC Driver(32-bit)
Driver=/opt/mapr/drillodbc/lib/32/libdrillodbc_sb32.so

[MapR Drill ODBC Driver 64-bit]
Description=MapR Drill ODBC Driver(64-bit)
Driver=/opt/mapr/drillodbc/lib/64/libdrillodbc_sb64.so

mapr.drillodbc.ini

[Driver]

DisableAsync=0
DriverManagerEncoding=UTF-16
ErrorMessagesPath=/opt/mapr/drillodbc/ErrorMessages
LogLevel=0
LogPath=[LogPath]
SwapFilePath=/tmp
ODBCInstLib=/usr/lib/x86_64-linux-gnu/libodbcinst.so.1.0.0

最后,如果您已正确安装并配置了ODBC驱动程序,那么命令python -c 'import pyodbc; print(pyodbc.dataSources()); print(pyodbc.connect("DSN=drill64", autocommit=True))'应该输出如下信息:

{'ODBC': '', 'drill64': '/opt/mapr/drillodbc/lib/64/libdrillodbc_sb64.so'} <pyodbc.Connection object at 0x7f5ec4a20200>

有关设置Apache Drill的更多信息,请查看此博客文章:http://www.bigendiandata.com/2017-05-01-Apache_Drill/

相关问题