How to fix: cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library - Python

后端 未结 4 1761
失恋的感觉
失恋的感觉 2021-01-01 18:45

I am establishing a connection to oracle 11g which is in a remote server using cx_oracle 7 with python 3.6.7. my OS in Ubuntu 18.04

I have installed oracle instant c

相关标签:
4条回答
  • 2021-01-01 18:55

    If you're working with aws lambdas to connect to your RDS/OracleDB, then try this approach using Docker to automated the build for the aws lambda layer - https://medium.com/@sabithvm/building-up-on-lambda-layers-a4771d3b9c7

    0 讨论(0)
  • 2021-01-01 19:03

    After some more research i got the solution from ubunu community , after you have installed oracle instantclient you will have to integrate oracle libraries as follows:

    export LD_LIBRARY_PATH=/usr/lib/oracle/<version>/client(64)/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}

    For example, 12.1 version for Linux x86_64:

    export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}

    where <version> indicates the version of your of your oracle intantclient e.g 11.2, 12.2
    The connection parameter should be as follows connection = cx_Oracle.connect("username/password@host/service_name e.g orcl")

    to get the listener/service_name type the following in the oracle sqlplus

    SQL> show parameter local_listener
    

    the value is the listener

    0 讨论(0)
  • 2021-01-01 19:07

    For Ubuntu Linux 20.04 LTS server what worked for me (which may be obvious but wasn't to me!) is 1) when you perform the export, you need to be in the folder you intend to run the app/ command connecting to Oracle from, and although this worked, after closing the SSH terminal to the EC2 server, was then not available again which was resolved by 2) Add it to ~/.bashrc Steps in full:

    With the Oracle instant client unzipped in for example: /opt/oracle/instantclient_19_9

    sudo apt-get install libaio1
    cd ~/your-project-folder
    export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_9
    

    I then added to ~/.bashrc with:

    sudo nano ~/.bashrc
    

    And add this line:

    export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_9
    

    And in the terminal run:

    source ~/.bashrc
    

    Mine worked as expected installed on an EC2 server under 'ubuntu' user with requisite nvm/ nodeJs installed

    In nodeJs an example connection might look something like:

    const testOracleConnection = async () => {
        let conn;
    
        try {
            conn = await oracledb.getConnection(oracleConfig);
    
            const query1 = 'select ID, anotherColumn from someTable where ID = 1111';
    
            const result = await conn.execute(query1);
    
            console.log(result);
        } catch (err) {
            console.error(err);
        } finally {
            if (conn) {
                try {
                    await conn.close();
                } catch (err) {
                    console.error(err);
                }
            }
        }
    };
    
    0 讨论(0)
  • 2021-01-01 19:14

    I was facing the exact same problem. This is what worked for me:

    • First, I downloaded the Oracle Basic zip file. In my case, I got the 64-bit version.
    • After that, I unzipped it in an opt directory. I had to use sudo in my system
        $ sudo mkdir -p /opt/oracle  
    
        $ cd /opt/oracle  
    
        $ sudo unzip /opt/oracle/instantclient-basic-linux.x64-19.8.0.0.0dbru.zip  
    
    • Then I installed libaio1. Note that I am working with Ubuntu
        $ sudo apt-get install libaio1
    
    • Finally, I added the path to the external variable LD_LIBRARY_PATH
        $ vim ~/.bashrc  
    
    • And added this line to the .bashrc file
        export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_8:$LD_LIBRARY_PATH  
    
    • After saving the .bashrc file, I sourced it:
        $ source ~/.bashrc
    

    Then my Python script worked nicely again.

    See also the cx_oracle documentation

    0 讨论(0)
提交回复
热议问题