Python2.5提供了标准的PEP 249 -- Python Database API Specification v2.0,可以使用基本一致的接口来访问各种类型的数据库,对应于ASE数据库,则有开源的python-sybase实现了该接口,从Web站点http://python-sybase.sourceforge.net上可以下载到该模块。
1.1 安装python-sybase模块
首先,确保系统中已经安装好了Python,并且也安装了Sybase ASE客户端,它带有OpenClient,从环境变量%SYBASE%以及%SYBASE_OCS%可以判断得到(linux/unix下是$SYBASE和$SYBASE_OCS)。
另外,由于安装过程需要对其中的C程序进行编译和链接,Windows平台需要拥有Microsoft Visual Studio .NET 2003\Vc7来进行编译。
从http://downloads.sourceforge.net/python-sybase/python-sybase-0.38.tar.gz下载到python-sybase的模块压缩包,将其解压至目录:python-sybase-0.38,发现其目录结构如下:
E:\LEARN\PYTHON\REF\PYTHON-SYBASE-0.38
├─build
│ ├─lib.win32-2.5
│ └─temp.win32-2.5
│ └─Release
├─doc
├─*.c, *.py, *.h 等
└─examples
一般情况下,直接运行python setup.py install,直接就完成了python-sybase模块的安装,实际情况,可能有些不太一样,从它的网站上的平台支持列表,我们可以看到,目前在Windows平台上,似乎不支持Openclient15.0.x。
表10-1 python-sybase支持平台及ASE版本
Client | Server | ||
OS | Libraries | OS | Libraries |
Linux | Sybase ASE 15.0.1 (32bits) | Linux | Sybase ASE 15.0.1 |
Linux 64-bits | OpenClient 12.5 | Linux | Sybase ASE 12.5 |
Linux | Sybase ASE 12.5 (32bits) | Linux | Sybase ASE 12.5 |
Linux | Sybase ASE 11.9.2 | Linux | Sybase ASE 11.9.2 |
Linux | Sybase ASE 11.0.3 | Linux | Sybase ASE 11.0.3 |
Linux | FreeTDS | Linux | Sybase ASA 9.0.2 |
Mac OS X 10.4.x | FreeTDS 0.62 | Linux | Sybase ASE 12.5 |
Windows 2000 Prof SP1 | Sybase ASE 11.9.2 | Windows NT 4.0 | Sybase ASE 11.9.2 |
Windows NT 4.0 SP6 | Sybase ASE 11.9.2 | HPUX 10.20 | Sybase ASE 11.9.2 |
Windows 98 | Sybase ASE 11.9.2 | NT 4.0 SP6 | OpenClient 11.5 |
Windows 95 OSR2 | Sybase ASE 11.9.2 | Solaris 2.6 | OpenClient 11.5 |
Solaris 10 | Sybase ASE 15.0.1 (32bits) | Solaris 10 | Sybase ASE 15.0.1 |
Solaris 10 | Sybase ASE 12.5 (32bits) | Solaris 10 | Sybase ASE 12.5 |
Solaris 8 | Sybase ASE 15.0.1 (32bits) | Solaris 8 | Sybase ASE 15.0.1 |
Solaris 8 | Sybase ASE 12.5 (32bits) | Solaris 8 | Sybase ASE 12.5 |
SunOS 5.9 | OpenClient 12.0 | SunOS 5.9 | Sybase ASE 12.5 |
Solaris 2.6 | Sybase ASE 11.5.1 | Solaris 8 | OpenClient 11.5 |
Solaris 5.6 | Sybase ASE 11.0.3 | | |
AIX 5.3 | Sybase ASE 15.0.1 (32bits) | AIX 5.3 | Sybase ASE 15.0.1 |
AIX 5.2 | Sybase ASE 12.5 (32bits) | AIX 5.2 | Sybase ASE 12.5.1 |
IRIX 6.5 | 11.5.1 | | |
HP-UX 11 | 11.5.1 | | |
要支持Sybase ASE15.0及以上版本,需要手动修改setup.py中的有关代码。
我们从中找到下面的代码块:
elif os.name == 'nt': # win32
# Not sure how the installation location is specified under NT
if sybase is None:
sybase = r'i:\sybase\sql11.5'
if not os.access(sybase, os.F_OK):
sys.stderr.write(
'Please define the Sybase installation directory in'
'the SYBASE environment variable.\n')
sys.exit(1)
syb_libs = ['libblk', 'libct', 'libcs']
将其中的syb_libs = ['libblk', 'libct', 'libcs']替换为syb_libs = ['libsybblk', 'libsybct', 'libsybcs']即可。原因是在ASE15.0及以上版本,这三个动态库的名字都发生了变化。我在Sybase ASE15.0下安装这个包时发现了此问题。15.0以下版本,无需修改该文件就可以安装。
安装的命令是:python setup.py install
安装完以后,在python目录下边,我们会发现有下述安装好的文件:
Lib\site-packages\Sybase.py
Lib\site-packages\python_sybase-0.38-py2.5.egg-info
Lib\site-packages\sybasect.pyd
没有评论:
发表评论