How to install cx_Oracle on El Capitan
Asked Answered
C

5

6

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
Cryogenics answered 21/10, 2015 at 12:44 Comment(4)
Hi Greg, but did you run "cxOracleSIP.sh" ? because you are facing an OSX security issue rather than an Oracle client issue. RegardsFeer
Thanks. I believe the fix_oralib.rb also does the security fix. One idea I'm working on is that pip isn't installing the latest version.Cryogenics
There should be no SIP issues if you use the straight Instant Client 12.1 libraries. Just set the environment variable FORCE_RPATH=1 before installing cx_Oracle.Marienbad
Also, LD_LIBRARY_PATH is a Linux-thing, and DY_LIBRARY_PATH isn't used because of the SIP issue. So no need to set those variables.Marienbad
C
0

I think I fixed it. Basically everything in my steps posted above were correct.

But I ended up using this for the pip install to make sure it pulls down a new copy and rebuilds (and maybe gets a later version??)

$ pip install --no-cache-dir --allow-external --allow-unverified cx_oracle

I was then able to import cx_oracle without issues but I was getting an error "'ORA-21561: OID generation failed'" when connecting to the external server.

Then I followed the instructions here and added a line with my host name to the /etc/hosts file and it all works now.

e.g., added a line like this at the end of /etc/hosts

127.0.0.1 localhost my-host-name

Cryogenics answered 22/10, 2015 at 15:36 Comment(0)
P
8

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.

Pendergast answered 21/7, 2016 at 18:26 Comment(5)
There shouldn't be any SIP issues if you use the Instant Client 12.1 libraries and export FORCE_RPATH=1 before installing. If you check cx_Oracle's setup.py you can see this variable causes -rpath to be added to the link line.Marienbad
Verified that there are no SIP issues with instantclient 12.1, as long as you run export FORCE_RPATH=1 before running pip install cx_Oracle. The above answer essentially does what pip would do...the linked post above has also been updated.Pendergast
A couple simplifications/comments on the linked post: (i) cx_Oracle uses OCI not OCCI, so technically there is no need for the libocci symbolic link (ii) ORACLE_HOME is only used by setup.py during installation so you don't need it in .bashrc. In general ORACLE_HOME should not be set when using Instant Client, but cx_Oracle overloads its use and needs it for installation (iii) because of the use of rpath you don't need to set DYLD_LIBRARY_PATH. Hope these help make it simpler.Marienbad
The linked post has been updated with all 3 suggestions above. Credit has also been given to @ChristopherJones at the bottom of the article.Pendergast
I started getting errors after upgrading to Sierra. By setting FORCE_RPATH=1, uninstalling, and reinstalling with pip install --no-cache-dir --allow-external --allow-unverified cx_oracle (note I had to use all those options. just doing the normal install didn't do it. Now working. Thanks!Ns
H
2

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
Histology answered 29/2, 2016 at 3:41 Comment(1)
FWIW, cx_Oracle doesn't use C++ so you don't need the libocci symbolic link. You only need the libclntsh link.Marienbad
C
0

I think I fixed it. Basically everything in my steps posted above were correct.

But I ended up using this for the pip install to make sure it pulls down a new copy and rebuilds (and maybe gets a later version??)

$ pip install --no-cache-dir --allow-external --allow-unverified cx_oracle

I was then able to import cx_oracle without issues but I was getting an error "'ORA-21561: OID generation failed'" when connecting to the external server.

Then I followed the instructions here and added a line with my host name to the /etc/hosts file and it all works now.

e.g., added a line like this at the end of /etc/hosts

127.0.0.1 localhost my-host-name

Cryogenics answered 22/10, 2015 at 15:36 Comment(0)
M
0

To install cx_Oracle on OS X, download the 64 bit Instant Client basic & sdk packages for OS X from http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html. With this version of Instant Client you can connect to 10g, 11g and 12c databases. This version is linked in a way to avoid the SIP problem Apple recently introduced (which affected Instant Client 11.2).

Then run something like:

unzip instantclient-basic-macos.x64-12.1.0.2.0.zip
unzip instantclient-sdk-macos.x64-12.1.0.2.0.zip
cd instantclient_12_1
ln -s libclntsh.dylib.12.1 libclntsh.dylib
cd ..
export ORACLE_HOME=`pwd`/instantclient_12_1
export FORCE_RPATH=1
pip install cx_Oracle

You may or may not need other pip options, as mentioned in https://mcmap.net/q/1678405/-how-to-install-cx_oracle-on-el-capitan

Marienbad answered 22/7, 2016 at 1:16 Comment(0)
A
0

Also notice: if your python run as 32 bit, and installed cx_Oracle as 64 bit, you will also meet this issue. To avoid this issue, always run your command as super user 'su' and get clear 'su' python is 32 bit or 64 bit. check your python bit How do I determine if my python shell is executing in 32bit or 64bit mode on OS X?

force using 64bit run:

arch -x86_64 /usr/bin/python27

force using 32bit run :

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

Apteral answered 22/7, 2017 at 14:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.