Вопрос

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)

Это было полезно?

Решение

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.

Другие советы

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...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top