开发者

libclntsh.so.11.1: cannot open shared object file.

开发者 https://www.devze.com 2022-12-27 21:53 出处:网络
I want to schedule a task on Linux by icrontab, and the task is written in python and have to import cx_Oracle module, so I export ORACLE_HOME and LD_LIBRARY_PATH in .bash_profile, but

I want to schedule a task on Linux by icrontab, and the task is written in python and have to import cx_Oracle module, so I export ORACLE_HOME and LD_LIBRARY_PATH in .bash_profile, but it raise the error:

libclntsh.so.11.1: cannot open shared object file.

Since it is ok to run the task by issue the command in shell like:

python a.py  # ok

I change the task in icrontab into a shell script which invoke my Python script, but the exception recurred?

# the shell script sc开发者_开发百科heduled in icrontab
#! bash 
python a.py    

Could you help how to do with it?


Possibly you want to specify PATH — and also ORACLE_HOME and LD_LIBRARY_PATH — so that cron(1) knows where to find binaries.
Read "5 Crontab environment" here.


The libs are located in /u01/app/oracle/product/11.2.0/xe/lib (For Oracle XE) or similar.

You should add this path to /etc/ld.so.conf or if this file shows only an include location, as in a separate file in the /etc/ld.so.conf.d directory

I have oracle.conf in /etc/ld.so.conf.d, just one file with the path. Nothing else.

Of course don't forget to run ldconfig as a last step.


Cron does not load the user's profile when running a task and you have to include the profile in your shell script explicitly.

Example documentation


If you have problem with libclntsh.so, need create symlink for libclntsh.so from /usr/lib/oracle/11.2/client64/lib to /usr/lib


I ran into this same problem last weekend when I needed to use cx_Oracle. After spending a lot of time trying to modify the LD_LIBRARY_PATH variable to include the $ORACLE_HOME/lib directoy, where libclntsh.so resides, I ended up solving the problem by creating symbolic links from all the Oracle xlibx.so libraries into /lib/xlibx.so. This certainly isn't the "cleanest" solution, but it has a good chance of working without causing too much trouble:

 cd $ORACLE_HOME/lib
 for f in `ls ./*.so*`; do;
   sudo ln -s $ORACLE_HOME/lib/$f /lib/$f 
 done

After I did that, cx_Oracle worked like a charm.


This post helped me solve a similar problem with a PostgreSQL database link to Oracle using oracle_fdw.

I installed oracle_fdw but when I tried CREATE EXTENSION oracle_fdw; I got error could not load library libclntsh.so.11.1: cannot open shared object file: No such file or directory.

I checked $ORACLE_HOME, $PATH and $LD_LIBRARY_PATH.

It worked only AFTER I put Oracle Shared Library on Linux Shared Library

echo /opt/instantclient_11_2 > oracle.conf
ldconfig


I had to install the dependency

oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64


Just pass your Oracle path variables before you run any scripts:
Like for perl you can do add below in beginning of your script:

BEGIN {
   my $ORACLE_HOME     = "/usr/lib/oracle/11.2/client64";
   my $LD_LIBRARY_PATH = "$ORACLE_HOME/lib";
   if ($ENV{ORACLE_HOME} ne $ORACLE_HOME
   || $ENV{LD_LIBRARY_PATH} ne $LD_LIBRARY_PATH
   ) {
      $ENV{ORACLE_HOME}     = "/usr/lib/oracle/11.2/client64";
      $ENV{LD_LIBRARY_PATH} = "$ORACLE_HOME/lib";
      exec { $^X } $^X, $0, @ARGV;
   }
}


I always have this problem, I can solve by running the code below: export LD_LIBRARY_PATH=/opt/oracle/instantclient:$LD_LIBRARY_PATH

libclntsh.so.11.1: cannot open shared object file.

OBS: This code I saved in the configuration file because I always use it. good luck.


I have copied all library files from installer media databases/stage/ext/lib to $ORACLE_HOME/lib and it resolved the issue.


For the benefit of anyone else coming here by far the best thing to do is to update cx_Oracle to the latest version (6+). This version does not need LD_LIBRARY_PATH set at all.


probably you need to sudo into an account registered with relevant env settings :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号