install cx_oracle for python

后端 未结 11 1751
逝去的感伤
逝去的感伤 2021-01-30 04:27

Am on Debian 5, I\'ve been trying to install cx_oracle module for python without any success. First, I installed oracle-xe-client and its dependency (followed tutorial in the fo

11条回答
  •  礼貌的吻别
    2021-01-30 05:04

    This just worked for me on Ubuntu 16:

    Download ('instantclient-basic-linux.x64-12.2.0.1.0.zip' and 'instantclient-sdk-linux.x64-12.2.0.1.0.zip') from Oracle web site and then do following script (you can do piece by piece and I did as a ROOT):

    apt-get install -y python-dev build-essential libaio1
    mkdir -p /opt/ora/
    cd /opt/ora/
    
    ## Now put 2 ZIP files:
    # ('instantclient-basic-linux.x64-12.2.0.1.0.zip' and 'instantclient-sdk-linux.x64-12.2.0.1.0.zip') 
    # into /opt/ora/ and unzip them -> both will be unzipped into 1 directory: /opt/ora/instantclient_12_2 
    
    rm -rf /etc/profile.d/oracle.sh
    echo "export ORACLE_HOME=/opt/ora/instantclient_12_2"  >> /etc/profile.d/oracle.sh
    echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME"  >> /etc/profile.d/oracle.sh
    chmod 777 /etc/profile.d/oracle.sh
    source /etc/profile.d/oracle.sh
    env | grep -i ora  # This will check current ENVIRONMENT settings for Oracle
    
    
    rm -rf /etc/ld.so.conf.d/oracle.conf
    echo "/opt/ora/instantclient_12_2" >> /etc/ld.so.conf.d/oracle.conf
    ldconfig
    cd $ORACLE_HOME  
    ls -lrth libclntsh*   # This will show which version of 'libclntsh' you have... --> needed for following line:
    
    ln -s libclntsh.so.12.1 libclntsh.so
    
    pip install cx_Oracle   # Maybe not needed but I did it anyway (only pip install cx_Oracle without above steps did not work for me...)
    

    Your python scripts are now ready to use 'cx_Oracle'... Enjoy!

提交回复
热议问题