学习python过程中,因需要连接oracle数据库,所以要安装cx_Oracle。
我的电脑是WIN64,python是2.7版本,本地oracle client是32位的。安装过cx_Oracle-5.2.1-11g.win-amd64-py2.7 (Oracle 11g, Python 2.7)后,import cx_Oracle报错,提示importError: DLL load failed: 不是有效的Win32程序。看到dll后了想到cx_Oracle是要调用OCI来联接Oracle数据库的。我本机上的oracle_10g_client是32位的。一个64位的程序调用32位的动态库当然会出错了。
根据文章http://blog.youkuaiyun.com/huzhenwei/article/details/3946308指点,去oracle网站下载了instance client,地址是http://www.oracle.com/technology/software/tech/oci/instantclient/index.html。我下载了instantclient-basic-windows.x64-11.2.0.2.0.zip这个版本。解压缩后没有看到安装文件,百度看了一下发现不需要安装,只需要设置几个环境变量就行了。比如我把下载的instantclient-basic-nt-11.2.0.2.0.zip压缩包解压,放到 C:\instantclient_11_2 目录下。在“环境变量”的“系统变量”中增加:
ORACLE_HOME = C:\instantclient_11_2