centos 6.5 安装 cx_Oracle 5.12 步骤 ,使用oracle instantclient12.1

新建sh文件
内容如下:
以su用户执行这个文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
  
# INSTALL ORACLE INSTANT CLIENT #
#################################
  
# NOTE: Oracle requires at least 1176 MB of swap (or something around there).
# If you are using CentOS in a VMWare VM, there‘s a good chance that you don‘t have enough by default.
# If this describes you and you need to add more swap, see the
# "Adding a Swap File to a CentOS System" section, here:
  
# Install basic dependencies
sudo yum -y install libaio bc flex
  
echo "Now go get some the following two RPMs ..."
echo "- basic: oracle-instantclient12.1-basic-12.1.0.1.0-1.x86_64.rpm"
echo "- SDK/devel: oracle-instantclient12.1-devel-12.1.0.1.0-1.x86_64"
echo "WARNING: It‘s pretty annoying, they make you sign up for an Oracle account, etc."
echo ‘I will assume you have put these two files are into the same folder‘
echo "Press any key once you‘re ready" && read -n 1 -s
  
sudo rpm -ivh oracle-instantclient12.1-basic-*
sudo rpm -ivh oracle-instantclient12.1-devel-*
  
# SET ENVIRONMENT VARIABLES #
#############################
  
  
# (SIDENOTE: I had to alter it by doing some digging around for where the Oracle RPMs really installed to;
# if you ever need to do this, do a command like this:
#     rpm -qlp <rpm_file_of_concern.rpm>)
  
echo ‘# Convoluted undocumented Oracle bullshit.‘ >> $HOME/.bashrc
echo ‘export ORACLE_VERSION="12.1"‘ >> $HOME/.bashrc
echo ‘export ORACLE_HOME="/usr/lib/oracle/$ORACLE_VERSION/client64/"‘ >> $HOME/.bashrc
echo ‘export PATH=$PATH:"$ORACLE_HOME/bin"‘ >> $HOME/.bashrc
echo ‘export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$ORACLE_HOME/lib"‘ >> $HOME/.bashrc
. $HOME/.bashrc
  
# INSTALL cx_Oracle #
#####################
  
pip install cx_Oracle

  

 
 
 
 
 
 
如果执行出错,那么请下载cx_Oracle 5.12的源码进行编译
下载地址http://cx-oracle.sourceforge.net/
请对应python版本、OS版本
#python3 setup.py build install 
请修改setup.py中的
filesToCheck = [
                ("11g", "libclntsh.so.12.1"),
                ("10g", "libclntsh.so.10.1"),
                ("9i", "libclntsh.so.9.0")
因为我们安装的instantclient12.1是12.1版本,所以安装前检查文件的路径应该是libclntsh.so.12.1。
 
然后在python3中import cx_Oracle
不报错说明安装成功。
 

---更新 

如果出现ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory
说明路径不对,没有加载上
执行# find / -name libclntsh.so.*获得实际的路径是
/usr/lib/oracle/12.1/client64/lib/libclntsh.so.12.1
那么要把这个路径加载上

编辑/etc/ld.so.conf

gedit /etc/ld.so.conf

在最后一行输入获取的路径

/usr/lib/oracle/12.1/client64/lib/

 

别忘了最后#ldconfig一下

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。