安装源码中并无makefile,再看指令,原来是用python setup.py install来进行安装,大约setup.py中有相应编译指令吧。由于本机已安有sybase open client客户端 检查存在SYBASE系统变量后,即尝试执行python setup.py install。
提示需下载一个http://cheeseshop.python.org/packages/2.7/s/setuptools/setuptools-0.6c6-py2.7
.egg,脚本自动开始下载,结果以NOT FOUND出错告终。打开该网址,发现此工具已升级为06c11版本,并提供有egg和windows下的exe两种安装文件。直接下载exe版本,安装成功。看提示是将相应包安装至系统的Python目录下。
再次执行python setup.py install 本以为该出现sybase运行库文件的错误了,结果却是直接编译通过!看来是因为sybaes客户端安装比较完整,路径和环境变量配置正确的缘故。
看编译提示,它自动调用了VS9(VS2008)的C编译器和链接器,生成的sybasect.lib和Sybase.py已放入相应目录。还将一个egg文件和附属文件放入了Python目录。egg文件是什么东西?似乎是Python的一种安装包吧,且不管它,看来若编写使用此模块的Python程序时,发布用的模块安装文件也给准备好了。下面来测试下能否使用吧。
此模块网站提供的测试程序:
import sys, string, Sybase db = Sybase.connect('SYBASE', 'sa', '', 'sybsystemprocs') c = db.cursor() if len(sys.argv) > 1: c.execute('select c.text from syscomments c, sysobjects o' ' where o.name = @name and o.type = "P" and c.id = o.id' ' order by c.colid', {'@name': sys.argv[1]}) print string.join([row[0] for row in c.fetchall()], '') else: c.execute('select name from sysobjects where type = "P" order by name') print string.join([row[0] for row in c.fetchall()], '\n')
将连接参数改正确后,python cs.py 运行成功,打印出输出结果。
总结一下安装过程:
1 电脑上要有C编译器,如VS或gcc等,加入环境变量。
2 安装setuptools工具,如http://pypi.python.org/pypi/setuptools/0.6c11,因setup.py运行需要。
3 解压缩python-sybase-0.39,进入setup.py所在目录下,执行python setup.py install 进行编译。
编译后会自行安装至Python环境下。
下面是编译模块时的输出:
C:\python_sybase\python-sybase-0.39\python-sybase-0.39>python setup.py install --------------------------------------------------------------------------- This script requires setuptools version 0.6c6 to run (even to display help). I will attempt to download it for you (from http://cheeseshop.python.org/packages/2.7/s/setuptools/), but you may need to enable firewall access for this script first. I will start the download in 15 seconds. (Note: if this machine does not have network access, please obtain the file http://cheeseshop.python.org/packages/2.7/s/setuptools/setuptools-0.6c6-py2.7 .egg and place it in this directory before rerunning this script.) --------------------------------------------------------------------------- Downloading http://cheeseshop.python.org/packages/2.7/s/setuptools/setuptools-0. 6c6-py2.7.egg Traceback (most recent call last): File "setup.py", line 31, in <module> use_setuptools() File "C:\python_sybase\python-sybase-0.39\python-sybase-0.39\ez_setup.py", lin e 86, in use_setuptools egg = download_setuptools(version, download_base, to_dir, download_delay) File "C:\python_sybase\python-sybase-0.39\python-sybase-0.39\ez_setup.py", lin e 140, in download_setuptools src = urllib2.urlopen(url) File "C:\Python27\lib\urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 397, in open response = meth(req, response) File "C:\Python27\lib\urllib2.py", line 510, in http_response 'http', reqst, response, code, msg, hdrs) File "C:\Python27\lib\urllib2.py", line 429, in error result = self._call_chain(*args) File "C:\Python27\lib\urllib2.py", line 369, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 605, in http_error_302 return self.parent.open(new, timeout=req.timeout) File "C:\Python27\lib\urllib2.py", line 397, in open response = meth(req, response) File "C:\Python27\lib\urllib2.py", line 510, in http_response 'http', reqst, response, code, msg, hdrs) File "C:\Python27\lib\urllib2.py", line 435, in error return self._call_chain(*args) File "C:\Python27\lib\urllib2.py", line 369, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 518, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 404: Not Found C:\python_sybase\python-sybase-0.39\python-sybase-0.39>
手工安装该setuptool后:
........省略若干行......... 正在创建库 build\temp.win32-2.7\Release\sybasect.lib 和对象 build\temp.win32- 2.7\Release\sybasect.exp C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe -nologo -manifest build \temp.win32-2.7\Release\sybasect.pyd.manifest -outputresource:build\lib.win32-2. 7\sybasect.pyd;2 creating build\bdist.win32 creating build\bdist.win32\egg copying build\lib.win32-2.7\Sybase.py -> build\bdist.win32\egg copying build\lib.win32-2.7\sybasect.pyd -> build\bdist.win32\egg byte-compiling build\bdist.win32\egg\Sybase.py to Sybase.pyc creating st loader for sybasect.pyd byte-compiling build\bdist.win32\egg\sybasect.py to sybasect.pyc creating build\bdist.win32\egg\EGG-INFO copying python_sybase.egg-info\PKG-INFO -> build\bdist.win32\egg\EGG-INFO copying python_sybase.egg-info\SOURCES.txt -> build\bdist.win32\egg\EGG-INFO copying python_sybase.egg-info\dependency_links.txt -> build\bdist.win32\egg\EGG -INFO copying python_sybase.egg-info\top_level.txt -> build\bdist.win32\egg\EGG-INFO writing build\bdist.win32\egg\EGG-INFO\native_libs.txt zip_safe flag not set; analyzing archive contents... creating dist creating 'dist\python_sybase-0.39-py2.7-win32.egg' and adding 'build\bdist.win32 \egg' to it removing 'build\bdist.win32\egg' (and everything under it) Processing python_sybase-0.39-py2.7-win32.egg Copying python_sybase-0.39-py2.7-win32.egg to c:\python27\lib\site-packages Adding python-sybase 0.39 to easy-install.pth file Installed c:\python27\lib\site-packages\python_sybase-0.39-py2.7-win32.egg Processing dependencies for python-sybase==0.39 Finished processing dependencies for python-sybase==0.39
原创文章,作者:苏葳,如需转载,请注明出处:https://www.swmemo.com/253.html