新建sh文件
內容如下:
以su用戶執行這個文件
#!/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: # http://www.techotopia.com/index.php/Adding_and_Managing_CentOS_Swap_Space # 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 "... from this URL: http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html" 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 # ############################# # Source for this section: http://cx-oracle.sourceforge.net/BUILD.txt # (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一下