linux安装cx_oracle
2015-09-01 15:35
501 查看
1、下载oracle
instant client并安装
2、配置oracle环境
4、连接验证
若报错:没有cx_Oracle这个模块,但是cx_Oracle已经安装上了,说明python没有找到cx_Oracle.so这个文件.
cx_Oracle.so安装在python的site-packages这个目录下了.安装完python后Linux上存在两个这样的目录:
一个是:/usr/lib/python27/site-packages
另一个是:/usr/local/lib/python27/site-packages
看下当前的python所指向的site-packages是哪一个,然后将cx_oracle.so复制过去就可以了. 若报错: import cx_Oracle gave ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory表示没有找到instant client的动态库,check一下环境变量是否配置,是否生效,版本是否正确。看看是不是改完/etc/profile 后忘记 source 一下了.若报错:ImportError: ./cx_Oracle.so: undefined symbol: PyUnicodeUCS4_Decode
所以重新编译python
若是报:error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
或
ImportError: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
这是因为:
由于在系统的lib路径中找不到这个共享库。
注: 如果编译时加上了--enable-shared,才会编译这个共享库,默认的位置是python可执行程序所在目录的lib目录下,如/usr/local/python27
解决办法:
1. 可以使用如下方式编译Python以解决这个问题:
./configure --enable-shared --prefix=/usr/local/python27
make && make install
2. cp /usr/local/python27/lib/libpython2.7.so.1.0 /usr/local/lib
cd /usr/local/lib
ln -s libpython2.7.so.1.0 libpython2.7.so
3. 使用命令whereis libpython2.7.so.1.0得到如下结果就说明
libpython2.7.so.1: /usr/local/lib/libpython2.7.so.1.0
4. 如果whereis没有结果,或者还有import错误,可以尝试如下操作:
在/etc/ld.so.conf中加入新行/usr/local/lib
保存后,运行
/sbin/ldconfig
/sbin/ldconfig –v
再次验证,终于正常import了
instant client并安装
2、配置oracle环境
$unzip basic-11.1.0.70-linux-x86_64.zip $cd instantclient_11_1 $cp * /usr/lib #直接放到动态库搜索路径中,不需要额外的环境配置 或 $unzip basic-11.1.0.70-linux-x86_64.zip $cp -rf instantclient_11_1 /opt/ $vi /etc/profile export ORACLE_HOME=/opt/instantclient_11_1 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME $source /etc/profile3、pip --trusted-host pypi.python.org install cx_oracle安装即可
4、连接验证
1 2 | $python >>import cx_Oracle |
cx_Oracle.so安装在python的site-packages这个目录下了.安装完python后Linux上存在两个这样的目录:
一个是:/usr/lib/python27/site-packages
另一个是:/usr/local/lib/python27/site-packages
12345 | >>> import sys>>> print sys.path['', 'C:\\windows\\SYSTEM32\\python27.zip', 'D:\\Python27\\DLLs', 'D:\\Python27\\lib', 'D:\\Python27\\lib\\plat-win', 'D:\\Python27\\lib\\lib-tk', 'D:\\Python27', 'D:\\Python27\\lib\\site-packages'] |
1 | Google的信息:There <span class="keyword" style="font-weight: bold;">is</span> nothing wrong with Debian. Python supports two incompatible modes of operation <span style="color: #0000ff;"><span class="keyword" style="font-weight: bold; color: #333333;">for</span></span> Unicode, UCS2 (the <span style="color: #0000ff;"><span class="keyword" style="font-weight: bold; color: #333333;">default</span></span>), and UCS4. Debian uses the <span style="color: #0000ff;"><span class="keyword" style="font-weight: bold; color: #333333;">default</span></span>, Redhat uses UCS4. You need to recompile the extension <span style="color: #0000ff;"><span class="keyword" style="font-weight: bold; color: #333333;">for</span></span> UCS-<span class="number" style="color: #009999;">2</span> mode (i.e. <span class="keyword" style="font-weight: bold;">using</span> a Debian installation); <span class="keyword" style="font-weight: bold;">this</span> would fix the undefined symbol: PyUnicodeUCS4_Decode |
1 | ./configure --enable-shared --prefix=/usr/local/python27 -enable-unicode=ucs4 |
或
ImportError: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
这是因为:
由于在系统的lib路径中找不到这个共享库。
注: 如果编译时加上了--enable-shared,才会编译这个共享库,默认的位置是python可执行程序所在目录的lib目录下,如/usr/local/python27
解决办法:
1. 可以使用如下方式编译Python以解决这个问题:
./configure --enable-shared --prefix=/usr/local/python27
make && make install
2. cp /usr/local/python27/lib/libpython2.7.so.1.0 /usr/local/lib
cd /usr/local/lib
ln -s libpython2.7.so.1.0 libpython2.7.so
3. 使用命令whereis libpython2.7.so.1.0得到如下结果就说明
libpython2.7.so.1: /usr/local/lib/libpython2.7.so.1.0
4. 如果whereis没有结果,或者还有import错误,可以尝试如下操作:
在/etc/ld.so.conf中加入新行/usr/local/lib
保存后,运行
/sbin/ldconfig
/sbin/ldconfig –v
再次验证,终于正常import了
相关文章推荐
- oracle查看允许的最大连接数和当前连接数等信息
- oracle字段含%检索
- oracle审计
- JDK+tomcat+oracle架设环境搭建
- Oracle 中Clob 字段,转换为 String 类型
- Oracle+Ado.Net(五)
- oracle报错总结
- oracle获取时间
- 查询转换
- oracle分页
- oracle数据库字符集US7ASCII,在java中处理中文问题
- oracle表数据类型number对应java中BIgDecimal转int
- ORACLE wmsys.wm_concat()函数把某列数据整合到一起
- Oracle,实现一条记录的上移下移
- mysql可有类似oracle的nvl的函数
- Oracle GoldenGate 三、加密
- hiberante4连接oracle数据库入门
- oracle命令登录数据库
- ORACLE wmsys.wm_concat()函数把某列数据整合到一起
- oracle中查看sql语句的执行计划