Linux profile.d environment variables not working with cx_oracle in Python

This is a bit of a follow-up from my previous question: cx_Oracle does not recognize the installation location of Oracle software to install on Linux .

After I was able to install cx_oracle correctly, I wanted to set up my environment so that environment variables didn't have to be exported every time.

To do this, I wrote a shellscript that included these two export statements:

export ORACLE_HOME=/home/user1/instantclient_12_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME

      

And saved this .sh file in a folder /etc/profile.d/

.

When I log into the server again with PuTTY, the echo statements say that environment variables exist:

# echo $ORACLE_HOME
/home/user1/instantclient_12_1
# echo $LD_LIBRARY_PATH
:/home/user1/instantclient_12_1

      

But when I run some python code with cx_oracle I get the error:

ImportError: libclntsh.so.12.1: cannot open shared object file: No such file or directory

      

The code runs again when I re-enter the export commands for environment variables. After that, the cx_oracle code works fine.

Why are my environment variables not working as expected, even though they appear when I echo? And how can I get my environment variables to persist correctly?

The guides I've read say to do this with a shell script in /etc/profile.d/

because it's better not to edit /etc/profile

directly.

Update:

I tried adding two export lines to /etc/profile

, but I still get the same problem where environment variables exist when I echo, but I still get this error when trying to use cx_oracle in python:

ImportError: libclntsh.so.12.1: cannot open shared object file: No such file or directory

      

Are you missing some key information about defining environment variables?

Second update: I tried to initialize the environment with a shell script that I planned to run with code that calls cx_Oracle:

StartServer.sh content:

export ORACLE_HOME=/home/user1/instantclient_12_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
python3 ./UDPDBQuery.pyc

      

And I am trying to run the code in the background by executing:

bash StartServer.sh &

      

But I still run into the same error as before, as if I hadn't introduced the environment variables. It only works if I export the variables myself and then run the code again. When I log out, the code also stops running in the background. I am still very confused as to why it is not working.

Are environment variables unusable for cx_oracle unless I manually make an export statement for them?

0


source to share


1 answer


Ok, I found out that one of the two environment variables did not properly export the file .sh

to /etc/profile.d

, and doing $LD_LIBRARY_PATH

would give me No such file or directorytclient_12_1

, but $ORACLE_HOME

it does /home/user1/instantclient_12_1/: is a directory

.

The way I resolved this was to split the export expressions into two separate shell scripts in profile.d

.



Everything works now.

+1


source







All Articles