1、安装环境$sudo -s#输入管理员密码$apt-get update$apt-get install unixODBC-dev #没有这个安装不了pyodbc,会报错 command'x86_64-linux-gnu-gcc' failed with exit status1$apt-get install g++$apt-get install python-dev
2、安装pyodbc
进入pyodbc的压缩文件目录$tar zxvf pyodbc-3.0.6.tar.gz
$cd pyodbc-3.0.6
$python setup.py build$python setup.py install$cd ../$rm -rf pyodbc-3.0.6 #删除解压的文件夹
3、安装freeTDS
$tar zxvf freetds-stable.tgz #下载地址ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz$cd freetds-0.91
$./configure --prefix=/usr/local/freetds --with-tdsver=8.0--enable-msdblib --enable-dbmfix --with-gnu-ld --enable-shared--enable-static$make$make install$cd ../$rm -rf freetds-0.91
配置相应的库文件$vi /etc/ld.so.conf #或者 gedit /etc/ld.so.conf在新起一行插入 /usr/local/freetds/lib,保存退出,$ldconfig #使更改生效。
4、配置freetds$vi /usr/local/freetds/etc/freetds.conf #gedit /usr/local/freetds/etc/freetds.conf末尾加入:[Sybase] host = XXX.XXX.XXXX.XXXX #IP地址 port = XXXXX #端口 tds version = 5.0 client charset = UTF-8
5、配置odbc文件$tar zxvf unixODBC-2.3.2.tar.gz$cd unixODBC-2.3.2$./configure$make$make install$cd ../$rm -rf unixODBC-2.3.2
#UNIXODBC的配置文件主要是usr/local/etc/odbcinst.ini以及usr/local/etc/odbc.ini。前者用于配置驱动程序,后者用于保存系统DSN。#转载请注明来源:http://blog.163.com/rihui_7/blog/static/21228514320153311217220/
$vi /etc/odbc.ini # gedit /etc/odbc.ini
加入:[ODBC Data Sources]SybaseDSN= sybasedsn
[sybasedsn]Driver = /usr/local/freetds/lib/libtdsodbc.soDescription = Sybase DSNTrace = NoServername = Sybase #这里来自freetds.config里面Database = JKCS
6.访问sybase数据库python
import pyodbc
conn = pyodbc.connect("DSN=SybaseDSN;UID=sa;pwd=")cursor = conn.cursor()cursor.execute("select * from LINE")
for row in cursor: print row
conn.close()
#转载请注明来源:http://blog.163.com/rihui_7/blog/static/21228514320153311217220/