2

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.

Kennard
  • 845
  • 2
  • 12
  • 32

2 Answers2

7

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.

Community
  • 1
  • 1
Alex Poole
  • 183,384
  • 11
  • 179
  • 318
  • It's been very nice of you, Alex. I tried to reinstall the whole thing(make sure everything is 64-bit). When I run the project, it got an ImportError: `ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): Library not loaded: /ade/dosulliv_ldapmac/oracle/ldap/lib/libnnz11.dylib Referenced from: /usr/local/lib/share/oracle/instantclient_11_2/libclntsh.dylib.11.1` I modified the commands that modify the cx_Oracle.so library to use the actual path. The second command leads to: – Kennard Feb 08 '16 at 16:34
  • `error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: can't open input file: /usr/local/lib/share/oracle/instantclient_11_2/libclntsh.dylib.11.1 for writing (Permission denied) error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: can't lseek to offset: 0 in file: /usr/local/lib/share/oracle/instantclient_11_2/libclntsh.dylib.11.1 for writing (Bad file descriptor) ` – Kennard Feb 08 '16 at 16:35
  • `error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: can't write new headers in file: /usr/local/lib/share/oracle/instantclient_11_2/libclntsh.dylib.11.1 (Bad file descriptor) error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: can't close written on input file: /usr/local/lib/share/oracle/instantclient_11_2/libclntsh.dylib.11.1 (Bad file descriptor)` – Kennard Feb 08 '16 at 16:35
  • OK, you have the 11.2.0.4 instant client now; which is fine but that seems to be built with different permissions. Just `chmod 755 libclntsh.dylib.11.1` before running the second step. – Alex Poole Feb 08 '16 at 16:42
  • Seem almost there. Now when I run the project. I didn't got an ImportError. It's `cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle ` Does it have anything to do with LD_LIBRARY_PATH or similar? – Kennard Feb 08 '16 at 16:45
  • No idea, sorry. The tests work for me, I don't have any knowledge beyond that. I'd guess your project is looking for credentials or a TNS alias or something. [From here](http://stackoverflow.com/q/13589683/266304) did you export ORACLE_HOME? Maybe your project needs to set that too. Good luck. Also please see if you can delete some of these comments as they should mostly be redundant now. – Alex Poole Feb 08 '16 at 16:52
  • I followed the same procedure with install_name_tool and got the same error: cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle – Eric Feb 13 '16 at 01:48
  • @Eric - as with Julia, this haas solved the original issue and it looks like a project or environment set-up problem, maybe. If you can't figure it out you should ask a new question specifically about that. – Alex Poole Feb 13 '16 at 09:00
-1

sample fix with

ln -s /opt/oracle/product/12.1.0/instantclient_12_1/libclntsh.dylib.12.1 /usr/local/lib/libclntsh.dylib.12.1
Chris Travers
  • 25,424
  • 6
  • 65
  • 182
Renee Ju
  • 1
  • 1