Can't get cx_Oracle to work with Python version 2.7 / mac os 10.7.2 (Lion) - missing_OCIAttrGet
Solution 1
If you are using the Apple-supplied Python 2.7, it will prefer to run in 64-bit mode and that will be a problem if you did install 32-bit-only Oracle libraries. You can try forcing that Python to run in 32-bit mode by starting it this way:
arch -i386 python2.7
If you are careful to always launch python via /usr/bin/python
, you could also use either of the methods described in Apple's man
page for Python, i.e. setting a VERSIONER_PYTHON_PREFER_32_BIT
environment variable or setting a permanent default via defaults
.
Solution 2
To compile cx_Oracle so it'll work on OS X needs a couple of things configured. The important bits are:
-
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
-
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
Solution 3
Not certain if you're still having problems with this, but here is how I got it to work.
I followed the instructions listed here (using the 32-bit downloads from Oracle): http://www.xairon.net/2011/05/guide-installing-cx_oracle-on-mac-os-x/
I then had the same error you listed:
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
The problem was from Apple's Python distribution running in 64-bit mode by default.
Once I forced the Apple supplied Python to use 32-bit (from Ned's recommendation), it worked!
To do that:
$export VERSIONER_PYTHON_PREFER_32_BIT=Yes
To make it permanent:
$defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
Solution 4
Steps to install to oracle client on mac ox 10.8.5 for connecting oracle from python. (There is bug due to it 64 bit doesn't work for mac ox 10.8.5 )
- Go to http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
- Download instantclient-basic-macos.x32-11.2.0.3.0.zip
- Download instantclient-sdk-macos.x32-11.2.0.3.0.zip
- Create new folder under /Users/< your username>/ora_32(you can name what you want )
-
Move the zip files instantclient-sdk-macos.x32-11.2.0.3.0.zip and instantclient-basic-macos.x32-11.2.0.3.0.zip to /Users/< your username>/ora_32 Command below
mv insta*32* /Users/< your username>/ora_32/
-
Unzip instantclient-basic-macos.x32-11.2.0.3.0.zip and instantclient-sdk-macos.x32-11.2.0.3.0.zip Command below
cd /Users/< your username>/ora_32/ unzip instantclient-basic-macos.x32-11.2.0.3.0.zip unzip instantclient-sdk-macos.x32-11.2.0.3.0.zip
- it will create a folder instantclient_11_2 under /Users//ora_32/
-
cd to /Users/< your username>/ora_32/instantclient_11_2 and Create the below symbolic link which will be used in the installation of cx_Oracle.( Mentioned below )
ln -s libclntsh.dylib.11.1 libclntsh.dylib ln -s libocci.dylib.11.1 libocci.dylib
-
Export the environment variables for the current session or you can add them in bash profile to invoke every time you open a new terminal.
export ORACLE_HOME=/Users/<your username>/ora_32/instantclient_11_2 export LD_LIBRARY_PATH=$ORACLE_HOME export DYLD_LIBRARY_PATH=$ORACLE_HOME export VERSIONER_PYTHON_PREFER_32_BIT=yes export PATH=$PATH:/Users/<your username>/ora_32/instantclient_11_2
- Download cx_Oracle (option source code only) at the link http://cx-oracle.sourceforge.net
- Untar the cx_Oracle tar file and it will create a cx_Oracle-5.1.2 folder cd to that folder cx_Oracle-5.1.2
-
Run the below command it will install cx_Oracle and then
sudo easy_install cx_Oracle
- You can check by going to python prompt and typing import cx_Oracle
nycynik
Experienced Software Developer - Currently focused mostly on iOS and web development.
Updated on June 11, 2022Comments
-
nycynik almost 2 years
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 incxoracle.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.