Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
784 views
in Technique[技术] by (71.8m points)

macos - cx oracle ImportError

I followed this tutorial for installing cx_oracle on Mac. After some tweaks it was successful. I was using Mavericks earlier. Then I got an upgrade to El Capitan. That's where the disaster came in.

It stopped working. I couldn't find related files in the directory earlier. Due to System Integrity Protection, I go through the whole process again and installed this at usr/local/lib/share/oracle/installclient_11_2.

But now when I run the program. It throws this error message:

ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): Library not loaded: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
  Referenced from: /Library/Python/2.7/site-packages/cx_Oracle.so
  Reason: image not found

I tried a lot of solutions online, like https://gist.github.com/rmoff/5a70862f27d2284e9541, http://kevindalias.com/2014/03/26/how-to-set-up-cx_oracle-for-python-on-mac-os-x-10-89/

Still no luck on me:(

Any suggestions are welcome. Thanks in advance!

==========================================================================

UPDATE:

Found this post online, works magically on El Capitan. Delete the old install, start fresh following this intruction step-by-step.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is related to the system integrity protection (SIP) changes in El Capitan, which among other things prevents DYLD_LIBRARY_PATH being inherited by spawned processes.

You can modify the cx_Oracle.so library to use the actual path to the Oracle client library instead of the searched path that no longer works; make sure you have ORACLE_HOME still set to point to your actual instant client location, and also note that the exact path reported by ImportError should be used - the 3071542110 value may vary depending on the version/build of Instant Client you have installed:

export ORACLE_HOME=/usr/local/lib/share/oracle/installclient_11_2

install_name_tool -change 
  /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1 
  $ORACLE_HOME/libclntsh.dylib.11.1 
  /Library/Python/2.7/site-packages/cx_Oracle.so

... but then that library can't find another Oracle one:

ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): Library not loaded: /ade/b/3071542110/oracle/ldap/lib/libnnz11.dylib
  Referenced from: /usr/local/lib/share/oracle/installclient_11_2/libclntsh.dylib.11.1
  Reason: image not found

So you'd need to change that library too, which you may be less comfortable with:

install_name_tool -change 
  /ade/b/3071542110/oracle/ldap/lib/libnnz11.dylib 
  $ORACLE_HOME/libnnz11.dylib 
  $ORACLE_HOME/libclntsh.dylib.11.1

Depending on the exact client version/build you may need to make the file writable before running that command, with:

chmod 755 $ORACLE_HOME/libclntsh.dylib.11.1

With those changes I can run the cx_Oracle tests on El Capitan.

More into on install_name_change here.


It looks like the 12c instant client has been built in a way that avoids this issue, so upgrading to that is gong to be simpler than hacking around int he 11g files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...