1
votes

I am trying to use SQLAlchemy to connect to our Teradata environment and execute a query. I ran the script on a Windows 7 machine using an Anaconda Python 2.7 environment and Jupyter notebook. When I moved this to our Linux server and ran it in an Anaconda Python 2.7 environment it doesn't work. It complains that it can't find the driver Teradata. I have ran this as root and my non-root user.

I am trying to run this in a Jupyter notebook running on the server

from sqlalchemy import create_engine
# connect
td_engine = create_engine('teradata://username:password@teradata_database:22/')

# execute sql
sql="SELECT * FROM sometable"
result = td_engine.execute(sql)

Here is the traceback

Here is what I've done on the RHEL 7 server inside a py27 env

conda install sqlalchemy

pip install teradata

pip install sqlalchemy-teradata

yum install unixODBC

I downloaded the latest Teradata ODBC Driver for Linux

I extracted the file

tar -zxf tdodbc1510__linux_indep_15.10.01.04-1.tar.gz

This gives me three more tar.gz files and a text file of the same name.

I then extract each of these tar.gz files

tar -zxf tdicu1510__linux_indep.15.10.04-1.tar.gz

tar -zxf tdodbc1510__linux_indep.15.10.01.04-1.tar.gz

tar -zxf TeraGSS_linux-x64_linux_indep.15.10.03.02-1.tar.gz

This creates a directory for each root name (tdicu1510, tdodbc1510, TeraGSS)

I cd into each directory and switch to korn shell

/usr/bin/ksh

for the rpm's inside the three directories I install them

rpm -ihv tdicu1510_linux_x64-15.10.03.02-1.noarch.rpm

rpm -ihv TeraGSS_linux_x64-15.10.03.02-1.noarch.rpm

rpm -ihv tdodbc1510_linux_x64-15.10.03.02-1.noarch.rpm

This creates an /opt/teradata directory

I add this to /usr/local/etc/odbcinst.ini

[Teradata]
Driver=/opt/teradata/client/15.10/odbc_64/lib/tdata.so
APILevel=CORE
ConnectFunctions=YYY
DriverODBCVer=3.51
SQLLevel=1

I add this to /usr/local/etc/odbc.ini

[ODBC Data Sources]
TDDSN=tdata.so

[ODBC]
InstallDir=/opt/teradata/client/15.10/odbc_64
Trace=0
TraceDll=/opt/teradata/client/15.10/odbc_64/lib/odbctrac.so
TraceFile=/usr/teradata_logs/odbcusr/trace.log
TraceAutoStop=0

[TDDSN]
Driver=/opt/teradata/client/15.10/odbc_64/lib/tdata.so
Description=Teradata database
DBCName=<MachineName or ip>
LastUser=
Username=
Password=
Database=

Here is my ~/.bashrc

export PATH="/opt/miniconda2/bin:$PATH
export ORACLE_HOME="/usr/lib/oracle/12.1/client64"
export PATH="$PATH:$ORACLE_HOME/bin"
export LD_LIBRARY_PATH="$ORACLE_HOME/lib"
export TNS_ADMIN="$ORACLE_HOME/network/admin"
export TERADATA="/opt/teradata/client/15.10"
export ODBCINI="/opt/teradata/client/15.10/odbc_64/odbc.ini"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TERADATA/lib64"

echo $LD_LIBRARY_PATH shows /usr/lib/oracle/12.1/client64/lib:/opt/teradata/client/15.10/lib64

Any ideas what I am doing wrong? Why can't SQLAlchemy see the Teradata ODBC driver on the Linux server?

1

1 Answers

2
votes

I too had the same issue. I overcame that by using python teradatasqlalchemy module and modifying the connection string from:

create_engine('**teradata**://username:password@teradata_database:22/')

to

create_engine('**teradatasql**://username:password@teradata_database:22/')