简体   繁体   中英

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

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.

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

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.

eg, added a line like this at the end of /etc/hosts

127.0.0.1 localhost my-host-name

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://stackoverflow.com/a/33284974/4799035

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM