install cx_oracle for python

后端 未结 11 1753
逝去的感伤
逝去的感伤 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:03

    The alternate way, that doesn't require RPMs. You need to be root.

    1. Dependencies

      Install the following packages:

      apt-get install python-dev build-essential libaio1
      
    2. Download Instant Client for Linux x86-64

      Download the following files from Oracle's download site:

    3. Extract the zip files

      Unzip the downloaded zip files to some directory, I'm using:

      /opt/ora/
      
    4. Add environment variables

      Create a file in /etc/profile.d/oracle.sh that includes

      export ORACLE_HOME=/opt/ora/instantclient_11_2
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
      

      Create a file in /etc/ld.so.conf.d/oracle.conf that includes

      /opt/ora/instantclient_11_2
      

      Execute the following command

      sudo ldconfig
      

      Note: you may need to reboot to apply settings

    5. Create a symlink

      cd $ORACLE_HOME 
      ln -s libclntsh.so.11.1 libclntsh.so
      
    6. Install cx_Oracle python package

      • You may install using pip

        pip install cx_Oracle
        
      • Or install manually

        Download the cx_Oracle source zip that corresponds with your Python and Oracle version. Then expand the archive, and run from the extracted directory:

        python setup.py build 
        python setup.py install
        
    0 讨论(0)
  • 2021-01-30 05:04

    I recommend that you grab the rpm files and install them with alien. That way, you can later on run apt-get purge no-longer-needed.

    In my case, the only env variable I needed is LD_LIBRARY_PATH, so I did:

    echo export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client/lib >> ~/.bashrc
    source ~/.bashrc
    

    I suppose in your case that path variable will be /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib.

    0 讨论(0)
  • 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!

    0 讨论(0)
  • 2021-01-30 05:05

    Alternatively you can install the cx_Oracle module without the PIP using the following steps

    1. Download the source from here https://pypi.python.org/pypi/cx_Oracle [cx_Oracle-6.1.tar.gz ]
    2. Extract the tar using the following commands (Linux)

      gunzip cx_Oracle-6.1.tar.gz

      tar -xf cx_Oracle-6.1.tar

    3. cd cx_Oracle-6.1

    4. Build the module

      python setup.py build

    5. Install the module

      python setup.py install

    0 讨论(0)
  • 2021-01-30 05:11

    Try to reinstall it with the following code:

    !pip install --proxy http://username:windowspwd@10.200.72.2:8080 --upgrade --force-reinstall cx_Oracle
    
    0 讨论(0)
提交回复
热议问题