Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install cx_Oracle on El Capitan

As I understand it, there was some change related to SIP that makes installing this difficult.

These pages have the background and advice to install. http://sourceforge.net/p/cx-oracle/mailman/message/34534872/, http://stefanoapostolico.com/2015/10/08/install_cx_oracle_with_sip_enabled.html

Putting all this together, here was my best shot at installing it to my virtualenv but alas, still no good.

The error I'm getting is:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: dlopen(/Users/me/sx_direct_env/lib/python2.7/site-packages/cx_Oracle.so, 2): Library not loaded: /b/227/rdbms/lib/libclntsh.dylib.10.1
  Referenced from: /Users/me/sx_direct_env/lib/python2.7/site-packages/cx_Oracle.so
  Reason: image not found

Here are all of my install steps:

$ cd /Users/me/sx_direct_env/lib/python2.7
$ mkdir oracle
$ cd oracle
$ export ORACLE_HOME=$PWD
$ export DYLD_LIBRARY_PATH=$ORACLE_HOME
$ export LD_LIBRARY_PATH=$ORACLE_HOME
$ export PATH=$PATH:$ORACLE_HOME
$ unzip ~/Downloads/instantclient-basic-macos.x64-11.2.0.4.0.zip
$ unzip ~/Downloads/instantclient-sdk-macos.x64-11.2.0.4.0.zip
$ mv instantclient_11_2/* .
$ rmdir instantclient_11_2
$ curl -O https://raw.githubusercontent.com/kubo/fix_oralib_osx/master/fix_oralib.rb
$ ruby -a fix_oralib.rb 
adrci:
   add rpath: @loader_path
   change install name
     from: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
       to: @rpath/libclntsh.dylib.11.1
   change install name
     from: /ade/dosulliv_ldapmac/oracle/ldap/lib/libnnz11.dylib
       to: @rpath/libnnz11.dylib

genezi:
   add rpath: @loader_path
   change install name
     from: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
       to: @rpath/libclntsh.dylib.11.1

libclntsh.dylib.11.1:
   add rpath: @loader_path
   change identification name
     from: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
       to: @rpath/libclntsh.dylib.11.1
   change install name
     from: /ade/dosulliv_ldapmac/oracle/ldap/lib/libnnz11.dylib
       to: @rpath/libnnz11.dylib

libnnz11.dylib:
   change identification name
     from: /ade/dosulliv_ldapmac/oracle/ldap/lib/libnnz11.dylib
       to: @rpath/libnnz11.dylib

libocci.dylib.11.1:
   change identification name
     from: /ade/b/3071542110/oracle/rdbms/lib/libocci.dylib.11.1
       to: @rpath/libocci.dylib.11.1

libociei.dylib:
   add rpath: @loader_path
   change install name
     from: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
       to: @rpath/libclntsh.dylib.11.1

libocijdbc11.dylib:
   add rpath: @loader_path
   change install name
     from: /ade/b/2475221476/oracle/rdbms/lib/libclntsh.dylib.11.1
       to: @rpath/libclntsh.dylib.11.1
   change install name
     from: /ade/b/2475221476/oracle/ldap/lib/libnnz11.dylib
       to: @rpath/libnnz11.dylib

uidrvci:
   add rpath: @loader_path
   change install name
     from: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
       to: @rpath/libclntsh.dylib.11.1
   change install name
     from: /ade/dosulliv_ldapmac/oracle/ldap/lib/libnnz11.dylib
       to: @rpath/libnnz11.dylib

$ pip install cx_oracle
Collecting cx-oracle
Installing collected packages: cx-oracle
Successfully installed cx-oracle-5.2

$ python -c "import cx_Oracle"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: dlopen(/Users/me/sx_direct_env/lib/python2.7/site-packages/cx_Oracle.so, 2): Library not loaded: /b/227/rdbms/lib/libclntsh.dylib.10.1
  Referenced from: /Users/me/sx_direct_env/lib/python2.7/site-packages/cx_Oracle.so
  Reason: image not found
like image 509
Greg Avatar asked Oct 21 '15 12:10

Greg


People also ask

Do you need Oracle client for cx_Oracle?

Using cx_Oracle requires Oracle Client libraries to be installed. These provide the necessary network connectivity allowing cx_Oracle to access an Oracle Database instance. Oracle Client versions 19, 18, 12 and 11.2 are supported.

How do you check cx_Oracle is installed or not?

You can check if you have the cx_Oracle package installed by running the pip show cx_Oracle command. Copied! The pip show cx_Oracle command will either state that the package is not installed or show a bunch of information about the package, including the location where the package is installed.


2 Answers

I attempted the above and got the following error while trying to install cx_Oracle using Oracle instantclient 12.1:

[535]: /opt/instantclient_12_1 $ python -c "import cx_Oracle"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): 
        Library not loaded: @rpath/libclntsh.dylib.12.1
  Referenced from: /Library/Python/2.7/site-packages/cx_Oracle.so
  Reason: image not found

Notice the @rpath in the error - it turns out that when building the cx_Oracle library (for instantclient 12.1) on El Capitan, the gcc compiler expects the -rpath flag to be set to know where to find the aforementioned dynamically linked libraries (*.dylib). By default, on instantclient 12.1, pip does not do this for you.

# Set -rpath option before installing...this will use $ORACLE_HOME during compilation
export FORCE_RPATH=TRUE
pip install cx_Oracle
# And verify cx_Oracle was correctly installed
python -c "import cx_Oracle"
# If this line fails install cx_Oracle with:
#   pip install --no-cache-dir --allow-external --allow-unverified cx_oracle

The python -c "import cx_Oracle" should report no errors.

For a complete install guide (including instantclient download and configuration) check out my post at http://thelaziestprogrammer.com/sharrington/databases/oracle/install-cx_oracle-mac for details.

like image 129
The Aelfinn Avatar answered Sep 18 '22 22:09

The Aelfinn


Thanks for the instructions Greg.

I had to create a symbolic link for my cx_Oracle pip install to work (using the arguments you provided above). You may want to add these to your instructions.

ln -s libclntsh.dylib.11.1 libclntsh.dylib

I also created another link for libocci as suggested from this install guide: https://gist.github.com/thom-nic/6011715

ln -s libocci.dylib.11.1 libocci.dylib
like image 28
somealias Avatar answered Sep 20 '22 22:09

somealias