`

为Sybase ASE15.x编译安装python-sybase模块

 
阅读更多
如果你有陈旧的vs2003编译器,那么这篇短文或者意义不是很大,
http://blog.donews.com/tekjian/archive/2006/08/06/990279.aspx 有简单的介绍如何直接安装这个玩意儿。
但是,现在很多人都用上了vs2005或者vs2008,可是python还是用的2.5.x版。这个时候痛苦就来了,
下载完python-sybase-0.38之后,如果你执行:
python setup.py intall,

肯定会出这样的错:

error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.

经过若干周折,发现,有办法绕过去,让vs2008直接支持编译安装。
先让sybase.bat环境变量生效,接着让vcvars.bat生效,(即执行这两个 bat)

把ASE15.x\OCS-150\lib下的三个文件libsyb*.lib,重命名为lib*.lib, 这三个新文件是:libct.lib, libcs.lib, libblk.lib

然后要修改python\Lib\distutils\msvccomiler.py, 找到:

    # x86  
    if self.__version >= 7:  
        self.__root = r"Software\Microsoft\VisualStudio"  
        self.__macros = MacroExpander(self.__version)  
    else:  
        self.__root = r"Software\Microsoft\Devstudio"  
注释掉这一行:self.__macros = MacroExpander(self.__version)

之后,把对应的pyc文件删掉,让它强制重新编译。

设置两个环境变量:set DISTUTILS_USE_SDK=1
set MSSdk=1

这之后执行python setup.py install, 就可以完全成功的安装了。

以下是详细的编译安装结果:

E:\learn\db_research\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.5/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.5/s/setuptools/setuptools-0.6c6-py2.5.egg

and place it in this directory before rerunning this script.)
---------------------------------------------------------------------------
Downloading http://cheeseshop.python.org/packages/2.5/s/setuptools/setuptools-0.6c6-py2.5.egg
running install
running bdist_egg
running egg_info
creating python_sybase.egg-info
writing python_sybase.egg-info\PKG-INFO
writing top-level names to python_sybase.egg-info\top_level.txt
writing dependency_links to python_sybase.egg-info\dependency_links.txt
writing manifest file 'python_sybase.egg-info\SOURCES.txt'
reading manifest file 'python_sybase.egg-info\SOURCES.txt'
writing manifest file 'python_sybase.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
creating build
creating build\lib.win32-2.5
copying Sybase.py -> build\lib.win32-2.5
running build_ext
building 'sybasect' extension
creating build\temp.win32-2.5
creating build\temp.win32-2.5\Release
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tcblk.c /Fobuild\temp.win32-2.5\Release\blk.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
blk.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tcdatabuf.c /Fobuild\temp.win32-2.5\Release\databuf.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
databuf.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tccmd.c /Fobuild\temp.win32-2.5\Release\cmd.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
cmd.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tcconn.c /Fobuild\temp.win32-2.5\Release\conn.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
conn.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tcctx.c /Fobuild\temp.win32-2.5\Release\ctx.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
ctx.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tcdatafmt.c /Fobuild\temp.win32-2.5\Release\datafmt.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
datafmt.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tciodesc.c /Fobuild\temp.win32-2.5\Release\iodesc.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
iodesc.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tclocale.c /Fobuild\temp.win32-2.5\Release\locale.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
locale.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tcmsgs.c /Fobuild\temp.win32-2.5\Release\msgs.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
msgs.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tcnumeric.c /Fobuild\temp.win32-2.5\Release\numeric.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
numeric.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tcmoney.c /Fobuild\temp.win32-2.5\Release\money.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
money.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tcdatetime.c /Fobuild\temp.win32-2.5\Release\datetime.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
datetime.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tcdate.c /Fobuild\temp.win32-2.5\Release\date.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
date.c
C:\tools\vs9\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GX /DNDEBUG -DWANT_BULKCOPY -DHAVE_DATETIME -DHAVE_DECIMAL -DHAVE_BLK_ALLOC -DHAVE_BLK_DESCRIBE -DHAVE_BLK_DROP -DHAVE_BLK_ROWXFER_MULT -DHAVE_BLK_TEXTXFER -DHAVE_CT_CURSOR -DHAVE_CT_DATA_INFO -DHAVE_CT_DYNAMIC -DHAVE_CT_SEND_DATA -DHAVE_CT_SETPARAM -DHAVE_CS_CALC -DHAVE_CS_CMP -ID:\sybase\OCS-15_0\include -Id:\tools\python\include -Id:\tools\python\PC /Tcsybasect.c /Fobuild\temp.win32-2.5\Release\sybasect.obj
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
sybasect.c
C:\tools\vs9\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:D:\sybase\OCS-15_0\lib /LIBPATH:d:\tools\python\libs /LIBPATH:d:\tools\python\PCBuild libblk.lib libct.lib libcs.lib /EXPORT:initsybasect build\temp.win32-2.5\Release\blk.obj build\temp.win32-2.5\Release\databuf.obj build\temp.win32-2.5\Release\cmd.obj build\temp.win32-2.5\Release\conn.obj build\temp.win32-2.5\Release\ctx.obj build\temp.win32-2.5\Release\datafmt.obj build\temp.win32-2.5\Release\iodesc.obj build\temp.win32-2.5\Release\locale.obj build\temp.win32-2.5\Release\msgs.obj build\temp.win32-2.5\Release\numeric.obj build\temp.win32-2.5\Release\money.obj build\temp.win32-2.5\Release\datetime.obj build\temp.win32-2.5\Release\date.obj build\temp.win32-2.5\Release\sybasect.obj /OUT:build\lib.win32-2.5\sybasect.pyd /IMPLIB:build\temp.win32-2.5\Release\sybasect.lib
LINK : fatal error LNK1181: cannot open input file 'libblk.lib'
error: command 'link.exe' failed with exit status 1181

E:\learn\db_research\python-sybase-0.39>python setup.py install
running install
running bdist_egg
running egg_info
writing python_sybase.egg-info\PKG-INFO
writing top-level names to python_sybase.egg-info\top_level.txt
writing dependency_links to python_sybase.egg-info\dependency_links.txt
reading manifest file 'python_sybase.egg-info\SOURCES.txt'
writing manifest file 'python_sybase.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
running build_ext
building 'sybasect' extension
C:\tools\vs9\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:D:\sybase\OCS-15_0\lib /LIBPATH:d:\tools\python\libs /LIBPATH:d:\tools\python\PCBuild libblk.lib libct.lib libcs.lib /EXPORT:initsybasect build\temp.win32-2.5\Release\blk.obj build\temp.win32-2.5\Release\databuf.obj build\temp.win32-2.5\Release\cmd.obj build\temp.win32-2.5\Release\conn.obj build\temp.win32-2.5\Release\ctx.obj build\temp.win32-2.5\Release\datafmt.obj build\temp.win32-2.5\Release\iodesc.obj build\temp.win32-2.5\Release\locale.obj build\temp.win32-2.5\Release\msgs.obj build\temp.win32-2.5\Release\numeric.obj build\temp.win32-2.5\Release\money.obj build\temp.win32-2.5\Release\datetime.obj build\temp.win32-2.5\Release\date.obj build\temp.win32-2.5\Release\sybasect.obj /OUT:build\lib.win32-2.5\sybasect.pyd /IMPLIB:build\temp.win32-2.5\Release\sybasect.lib
   Creating library build\temp.win32-2.5\Release\sybasect.lib and object build\temp.win32-2.5\Release\sybasect.exp
creating build\bdist.win32
creating build\bdist.win32\egg
copying build\lib.win32-2.5\Sybase.py -> build\bdist.win32\egg
copying build\lib.win32-2.5\sybasect.pyd -> build\bdist.win32\egg
copying build\lib.win32-2.5\sybasect.pyd.manifest -> build\bdist.win32\egg
byte-compiling build\bdist.win32\egg\Sybase.py to Sybase.pyc
creating stub loader for sybasect.pyd
byte-compiling build\bdist.win32\egg\sybasect.py to sybasect.pyc
creating build\bdist.win32\egg\EGG-INFO
writing python_sybase.egg-info\native_libs.txt
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
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist\python_sybase-0.39-py2.5-win32.egg' and adding 'build\bdist.win32\egg' to it
removing 'build\bdist.win32\egg' (and everything under it)
Processing setuptools-0.6c6-py2.5.egg
Copying setuptools-0.6c6-py2.5.egg to d:\tools\python\lib\site-packages
Adding setuptools 0.6c6 to easy-install.pth file
Installing easy_install-script.py script to d:\tools\python\Scripts
Installing easy_install.exe script to d:\tools\python\Scripts
Installing easy_install-2.5-script.py script to d:\tools\python\Scripts
Installing easy_install-2.5.exe script to d:\tools\python\Scripts

Installed d:\tools\python\lib\site-packages\setuptools-0.6c6-py2.5.egg
Processing dependencies for setuptools==0.6c6
Finished processing dependencies for setuptools==0.6c6
Processing python_sybase-0.39-py2.5-win32.egg
Copying python_sybase-0.39-py2.5-win32.egg to d:\tools\python\lib\site-packages
Adding python-sybase 0.39 to easy-install.pth file

Installed d:\tools\python\lib\site-packages\python_sybase-0.39-py2.5-win32.egg
Processing dependencies for python-sybase==0.39
Finished processing dependencies for python-sybase==0.39

经此实验,可以确定不一定要安装vc7,就可以安装一些要编译的python模块了。 当然,如果你机器上可以安装,最省事儿了。至于vc7,你完全可以自己整理出一个解压缩的绿色包,也就20来兆的样子。


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics