Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

macos - Can't get cx_Oracle to work with Python version 2.7 / mac os 10.7.2 (Lion) - missing_OCIAttrGet

Can't get cx_Oracle to work with Python version 2.7 / mac os 10.7.2 (Lion)

One other thing: I have installed oracle 32 bit, not sure if that was correct.

 Traceback (most recent call last):
      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
      Referenced from: /Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so
      Expected in: flat namespace
     in /Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so

They key problem seems to be not being able to locate _OCIAttGet, and I think this means that it cant find a lib file or something.

Found on the web, someone talking about DYLD_LIBRARY_PATH, but mine is set, however he mentioned it in cxoracle.cfg file, that I can not locate, is this my problem?

EDIT

After trying to run it with 32 bit mode python, I see a different error.

 Traceback (most recent call last):
   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 3, in __bootstrap__
 ImportError: No module named pkg_resources
  • I could not get the oracle 64 bit versions to run on my computer, kept getting segmentation faults when i ran sqlplus, so thats why I am using the 32.

SECOND EDIT

Actually no matter what i install, it is not the right version.. 32 bit version

 ld: warning: ignoring file /opt/oracle/instantclient10_2/libclntsh.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

64 bit version:

 ld: warning: ignoring file /opt/oracle/instantclient10_2/libclntsh.dylib, file was built for unsupported file format which is not the architecture being linked (x86_64)

I am going to try 11g, but that only has a 64 bit version.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To compile cx_Oracle so it'll work on OS X needs a couple of things configured. The important bits are:

  1. Create a virtualenv with a python interpreter stripped to 32-bit only. In the virtualenv bin directory ($WORKON_HOME/*name_of_virtualenv*/bin):

    % mv python python.fat
    % lipo python.fat -remove x86_64 -output python
    
  2. Even though Python is now thin its configuration is not so we need to force things using an obscure environment variable that distutils will pick up:

    ARCHFLAGS="-arch i386" pip install cx_Oracle
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...