0

Importing cx_Oracle in a python script fails.

I have cx_Oracle installed, using "pip install cx_oracle" - that worked fine, reported installed.

Now when i try:

import cx_Oracle

I get the following error

Traceback (most recent call last):
  File "reader.py", line 9, in <module>
    import cx_Oracle
ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): Symbol not found: _OCIAttrGet
  Referenced from: /Library/Python/2.7/site-packages/cx_Oracle.so
  Expected in: flat namespace
 in /Library/Python/2.7/site-packages/cx_Oracle.so

Other Information:

Python version 2.7 / mac os 10.7.2 (Lion)

$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin    
Type "help", "copyright", "credits" or "license" for more information.

Oracle 10.2

$ sqlplus -version    
SQL*Plus: Release 10.2.0.4.0 - Production

Also, I do not have a /bin directory at all in my ORACLE_HOME folder, I have only the instant client and SDK installed.

ox_Oracle

$ pip freeze
PyRSS2Gen==1.0.0
...
cx-Oracle==5.1.1

(found a lot of questions on getting cx_Oracle installed, but none on this - thanks)

2
  • i may have it, and will post my own answer, if its true. I was looking at the setup.py script, and noticed that it uses the folder names to guess the version. I have installed 10.2 in the 10.1 folder, maybe that is the issue. Commented Nov 17, 2011 at 14:36
  • OK, i manually installed CX_ORACLE instead of using pip, and now I have a slightlyt different, but basicly the same issue. File "reader.py", line 9, in <module> import cx_Oracle File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 7, in <module> File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 6, in bootstrap ImportError: dlopen(/Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so, 2): Symbol not found: _OCIAttrGet Commented Nov 17, 2011 at 15:15

2 Answers 2

2

I ran into this problem today and was able to solve it by changing path to the libraries referenced in the InstantClient binaries to the actual locations on the filesystem. This blog http://blog.caseylucas.com/2013/03/03/oracle-sqlplus-and-instant-client-on-mac-osx-without-dyld_library_path/ provides detailed explanation and the script to adjust all binaries. The only problem is that it uses @executable_path , which does not seem to work anymore with Python 2.7 & El Capitan (I'm not really sure what is responsible for the security exception). Replacing @executable_path with the actual path works just fine.

To summarize, steps to make it work:

  • install InstantClient to /usr/local/instantclient_11_2
  • make sure that cx_Oracle.so shared object that you use is at /Library/Python/2.7/site-packages/cx_Oracle.so
  • copy the following script to /usr/local/instantclient_11_2

    #!/bin/sh
    # script to change the dynamic lib paths and ids for oracle instant client
    # exes and libs
    (echo /Library/Python/2.7/site-packages/cx_Oracle.so ; find . -maxdepth 1 -type f \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print ) | while read exe
    do
        echo adjusting executable $exe
        baseexe=`basename $exe`
        otool -L $exe | awk '/oracle/ {print $1}' | while read lib
        do
            echo adjusting lib $lib
            baselib=`basename $lib`
            if [ "$baseexe" = "$baselib" ]
            then
                echo changing id to $baselib for $exe
                install_name_tool -id $baselib $exe
            else
                echo changing path id for $lib in $exe
                install_name_tool -change $lib /usr/local/instantclient_11_2/$baselib $exe
            fi
        done
    done
    
    • run the script with root permissions.
Sign up to request clarification or add additional context in comments.

Comments

-1

Uninstall everything.

Then install oracle instant client:

Then use pip to install cx_oracle.

Then set the path to point to the 32 bit version of oracle.

  • edit .profile file in your home directory and add the path to your oracle bin home, using this line:
  • export PATH=$PATH:/usr/local/lib/instantclient/

And it works...

5 Comments

and the magic words to "set mac os to use 32 bit mode" would be?
What I did was installed the oracle version that was 32 bit mode, and pointed the path to that directory.
How do you install the oracle client on a Mac in the first place?
export VERSIONER_PYTHON_PREFER_32_BIT=yes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.