简体   繁体   English

从Python连接到Oracle数据库

[英]Connecting to Oracle database from Python

Trying to connect to Oracle database from Python using cx-oracle. 尝试使用cx-oracle从Python连接到Oracle数据库。 I followed steps mentioned in this link: https://gist.github.com/thom-nic/6011715 我遵循了此链接中提到的步骤: https : //gist.github.com/thom-nic/6011715

I am running Python 2.7.8. 我正在运行Python 2.7.8。 on Yosemite(10.10.2).After I unzip instant client into this path on my machine: /Users/ayada/Library/Share/oracle which is set to ORACLE_HOME and have set both DYLD_LIBRARY_PATH, LD_LIBRARY_PATH to ORACLE_HOME. 在Yosemite(10.10.2)上将即时客户端解压缩到计算机上的以下路径后:/ Users / ayada / Library / Share / oracle,该路径设置为ORACLE_HOME,并将DYLD_LIBRARY_PATH,LD_LIBRARY_PATH都设置为ORACLE_HOME。 I use Pip(env ARCHFLAGS="-arch $ARCH" pip install cx_Oracle) to install cx_oracle but encountering following error: distutils.errors.DistutilsSetupError: 我使用Pip(env ARCHFLAGS =“-arch $ ARCH” pip install cx_Oracle)安装cx_oracle,但遇到以下错误:distutils.errors.DistutilsSetupError:

Oracle home (/Users/ayada/Library/Share/oracle) does not refer to an 9i, 10g, 11g or 12c installation. Oracle主目录(/ Users / ayada / Library / Share / oracle)不涉及9i,10g,11g或12c安装。

Cleaning up... Command python setup.py egg_info failed with error code 1 in /private/var/folders/22/78xh65wd3xq232p4zd18l8800013hw/T/pip_build_ayada/cx-Oracle Storing debug log for failure in /Users/ayada/.pip/pip.log 清理...命令python setup.py egg_info在/ private / var / folders / 22 / 78xh65wd3xq232p4zd18l8800013hw / T / pip_build_ayada / cx-Oracle中存储错误日志失败,错误日志为/Users/ayada/.pip/pip .log

To give some context, I don't have Oracle database installed on my machine but I am trying to connect to a remote server. 为了提供一些背景信息,我的计算机上没有安装Oracle数据库,但是我试图连接到远程服务器。

I am relatively newbie to working on Mac and doing these kind of setups. 我是在Mac上进行此类设置的新手。 Please advice. 请指教。

Have you done as kevindalias advised in the comments section of the link you pasted? 您是否已按照kevindalias在您粘贴的链接的“评论”部分中的建议进行操作?

Seems like Oracle made a change to the basic zip since this was posted, so to anyone else who arrives here: 自发布以来,似乎Oracle对基本zip进行了更改,因此到达此地的其他任何人都可以:

ln -s libclntsh.dylib.11.2 libclntsh.dylib ln -s libocci.dylib.11.2 libocci.dylib

should be... 应该...

ln -s libclntsh.dylib.11.1 libclntsh.dylib ln -s libocci.dylib.11.1 libocci.dylib

You'll see both 11.1 files when you unpack the zips, and the links need to point to them. 打开压缩包后,您将同时看到两个11.1文件,并且链接需要指向它们。 With this tweak, I was able to install cx_Oracle 5.1.2 on OS X 10.8.5 using 64-bit versions of Oracle Instant Client 11.2 and Python 2.7.6. 通过此调整,我能够使用64位版本的Oracle Instant Client 11.2和Python 2.7.6在OS X 10.8.5上安装cx_Oracle 5.1.2。 Good luck. 祝好运。

Also I don't know about Mac, but in RHEL, my ORACLE_HOME is different to LD_LIBRARY_PATH: 我也不了解Mac,但是在RHEL中,我的ORACLE_HOME与LD_LIBRARY_PATH不同:

LD_LIBRARY_PATH=$ORACLE_HOME/lib ORACLE_HOME=/usr/lib/oracle/12.1/client64

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

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