简体   繁体   English

python导入cygwin上的cx_Oracle错误

[英]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. 我试图从pypi源安装cx_Oracle,因为在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. 我确实按照http://permalink.gmane.org/gmane.comp.python.db.cx-oracle/2492的建议做了一些修改,并修改了我的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. TIA。

Fixed this by specifying the path to instantclient as below : 通过指定instantclient的路径修复此问题,如下所示:

$ 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 . 单从错误消息中很难确定,但我猜你在sys.path两个不同的cx_Oracle副本。 The error message is complaining that a different version of the same module had already been import -ed. 该错误消息抱怨已import相同模块的不同版本。

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 . 据推测,pristine上游版本是在/usr/lib/python2.7/site-packages/cx_Oracle-5.1.3-py2.7-cygwin-1.7.24-i686.egg系统范围内安装的,您的修改版本在/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? 如果你削减sys.path以便只包含原始版本或仅修改版本,它是否有效?

(You might want to use virtualenv if you need to switch back and forth between two versions frequently.) (如果需要经常在两个版本之间来回切换,可能需要使用virtualenv 。)

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. 对我来说,这可能是由于cygwin安装为64位,但即时客户端安装为32位不匹配造成的。 Double check that everything (oracle, cygwin) is either 32 bit or 64 bit. 仔细检查一切(oracle,cygwin)是32位还是64位。

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 由于我的cygwin是64位(请参阅uname -a ,并查找x86_64),我从oracle的网站下载了64位即时客户端,并解压缩

  2. I set the env vars in .profile, to point where it was unzipped: 我在.profile中设置env变量,指向解压缩的位置:

    export ORACLE_HOME=/cygdrive/c/oracle/instantclient_x64_11_2 export ORACLE_HOME = / cygdrive / c / oracle / instantclient_x64_11_2

    export LD_LIBRARY_PATH=$ORACLE_HOME export LD_LIBRARY_PATH = $ ORACLE_HOME

    export DYLD_LIBRARY_PATH=$ORACLE_HOME export DYLD_LIBRARY_PATH = $ ORACLE_HOME

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

  3. source ~/.profile 来源〜/ .profile

  4. To test, you should now be able to run this python command with no error: 要进行测试,您现在应该能够运行此python命令而不会出现错误:

    import cx_Oracle import cx_Oracle

To verify the path is correct, if you run ls , you should see something like 要验证路径是否正确,如果运行ls ,您应该看到类似的内容

ls $ORACLE_HOME 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM