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

后端 未结 4 1796
失恋的感觉
失恋的感觉 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 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);
                }
            }
        }
    };
    

提交回复
热议问题