简体   繁体   中英

python import cx_Oracle error on cygwin

I tried to install cx_Oracle from pypi source since there is no available port for it in cygwin. I did make some changes as suggested in http://permalink.gmane.org/gmane.comp.python.db.cx-oracle/2492 and modified my setup.py. However, I still get the following error :-

$ python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
/usr/lib/python2.7/site-packages/cx_Oracle-5.1.3-py2.7-cygwin-1.7.24-i686.egg/cx_Oracle.py:3: UserWa
rning: Module cx_Oracle was already imported from /usr/lib/python2.7/site-packages/cx_Oracle-5.1.3-p
y2.7-cygwin-1.7.24-i686.egg/cx_Oracle.pyc, but /home/zerog/cx_Oracle-5.1.3 is being added to sys.pat
h
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.cygwin-1.7.24-i686/egg/cx_Oracle.py", line 7, in <module>
  File "build/bdist.cygwin-1.7.24-i686/egg/cx_Oracle.py", line 6, in __bootstrap__
ImportError: Exec format error
>>>

If someone can please help me fix this ?

TIA.

Fixed this by specifying the path to instantclient as below :

$ export PATH=$PATH:/cygdrive/d/Tools/instantclient_11_2

(Other, possibly important stuff) :

$ echo $LD_LIBRARY_PATH
/cygdrive/d/Tools/instantclient_11_2
$ echo $ORACLE_HOME
/cygdrive/d/Tools/instantclient_11_2

Now, I get :-

$ python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>>

It's hard to pin down from the error message alone, but I am guessing that you have two different copies of cx_Oracle in your sys.path . The error message is complaining that a different version of the same module had already been import -ed.

Presumably the pristine upstream version is installed system-wide in /usr/lib/python2.7/site-packages/cx_Oracle-5.1.3-py2.7-cygwin-1.7.24-i686.egg , and your modified version in /home/zerog/cx_Oracle-5.1.3 .

Does it work if you pare down sys.path so that only the original, or only your modified version, is included?

(You might want to use virtualenv if you need to switch back and forth between two versions frequently.)

I ran into this error "Exec format error."

For me, this was likely caused by a mismatch between cygwin being installed as 64 bit, but the instant client being installed as 32 bit. Double check that everything (oracle, cygwin) is either 32 bit or 64 bit.

What fixed my issue:

  1. Since my cygwin is 64 bit (see uname -a , and look for x86_64), I downloaded the 64 bit instant client from oracle's website, and unzipped

  2. I set the env vars in .profile, to point where it was unzipped:

    export ORACLE_HOME=/cygdrive/c/oracle/instantclient_x64_11_2

    export LD_LIBRARY_PATH=$ORACLE_HOME

    export DYLD_LIBRARY_PATH=$ORACLE_HOME

    export TNS_ADMIN='//optional/path/to/your/oracle/tns/files/'

  3. source ~/.profile

  4. To test, you should now be able to run this python command with no error:

    import cx_Oracle

To verify the path is correct, if you run ls , you should see something like

ls $ORACLE_HOME

adrci.exe     genezi.exe  oci.sym        ociw32.dll  ojdbc6.jar          
oraocci11.dll   oraociei11.sym  uidrvci.exe  vc9
adrci.sym     genezi.sym  ocijdbc11.dll  ociw32.sym  orannzsbb11.dll  
oraocci11.sym   orasql11.dll    uidrvci.sym  xstreams.jar
BASIC_README  oci.dll     ocijdbc11.sym  ojdbc5.jar  orannzsbb11.sym
oraociei11.dll  orasql11.sym    vc8

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