oracle 如何在 RHEL 上为 Python 安装 cx_Oracle?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6442563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:03:56  来源:igfitidea点击:

How do you install cx_Oracle for Python on RHEL?

pythonoraclecx-oraclerhel

提问by damon

I'm using Active Python since I don't want to be stuck with an old version of Python. I installed the instant client, and added the exports to my bash profile, but I'm getting this cryptic error:

我正在使用 Active Python,因为我不想被旧版本的 Python 困住。我安装了即时客户端,并将导出添加到我的 bash 配置文件中,但我收到了这个神秘的错误:

# apy setup.py install --no-compile --root=/tmp/tmpz0JuWASA/cx_Oracle-5.1/_pypminstroot
running install
running build
running build_ext
building 'cx_Oracle' extension
gcc -pthread -fno-strict-aliasing -fPIC -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/lib/oracle/11.2/sdk/include -I/opt/ActivePython-2.7/include/python2.7 -c cx_Oracle.c -o build/temp.linux-x86_64-2.7-11g/cx_Oracle.o -DBUILD_VERSION=5.0.4
In file included from /opt/ActivePython-2.7/include/python2.7/Python.h:58,
                 from cx_Oracle.c:6:
/opt/ActivePython-2.7/include/python2.7/pyport.h:849:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
In file included from /usr/lib/oracle/11.2/sdk/include/oci.h:3029,
                 from cx_Oracle.c:10:
/usr/lib/oracle/11.2/sdk/include/ociap.h:10788: warning: function declaration isn't a prototype
/usr/lib/oracle/11.2/sdk/include/ociap.h:10794: warning: function declaration isn't a prototype
error: command 'gcc' failed with exit status 1

回答by Ben

I took all of this from this blog hereif you need more details.

我把所有这一切都从这个博客在这里,如果你需要更多的细节。

I did this and it worked perfectly. Here is the quick summary. First go get the oracle client stuff for your version of oracle (link is in blog)

我这样做了,而且效果很好。这是快速摘要。首先获取适用于您的 oracle 版本的 oracle 客户端内容(链接在博客中)

Then download to your /tmp/ folder and run the install

然后下载到您的 /tmp/ 文件夹并运行安装

rpm -ivh oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm

Now this was the part I struggled with, make sure ALL of your environmental variables are right. Also don't just copy these, go and confirm where your oracle stuff was installed.

现在这是我挣扎的部分,确保您的所有环境变量都是正确的。也不要只是复制这些,去确认你的 oracle 东西的安装位置。

echo export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.4/client64/lib/ >> ~/.bashrc
echo export ORACLE_HOME=/usr/lib/oracle/10.2.0.4/client64 >> ~/.bashrc
echo export PATH=$ORACLE_HOME/bin:$PATH >> ~/.bashrc

Now you can go to the ox_Oracle site, make sure to download the version that matches your version of python (if you are not sure run python -V) and your version of the oracle driver.

现在您可以访问 ox_Oracle 站点,确保下载与您的 python 版本匹配的版本(如果您不确定运行 python -V)和您的 oracle 驱动程序版本。

Download to your TMP folder, install and test with

下载到您的 TMP 文件夹,安装并测试

python -c "import cx_Oracle"

If that doesn't work check that blog, maybe I missed something. It worked for me on a fresh install. Thank goodness.

如果这不起作用,请查看该博客,也许我错过了一些东西。它在全新安装时对我有用。谢天谢地。

Sorry... not enough reputation points to give more live links... so you have to copy and paste or go to the blog.

对不起...没有足够的声望点来提供更多的实时链接...所以你必须复制和粘贴或转到博客。

回答by ARK

Make sure that you've a client sdk present in your path. Oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm which I tried did not come with the sdk. So I had to download zip version for it.

确保您的路径中存在客户端 sdk。我试过的oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm sdk没有自带。所以我不得不为它下载zip版本。

Add this to .bash_rc

将此添加到 .bash_rc

export DYLD_LIBRARY_PATH=$ORACLE_HOME

In addition to this, Python 2.7 does not come with Python.h which is available by default in Python 3.4. So I would also suggest to install python-devel package

除此之外,Python 2.7 没有附带 Python.h,它在 Python 3.4 中默认可用。所以我也建议安装 python-devel 包

yum install python-devel

That should resolve the issue.

那应该可以解决问题。

回答by Senthil Kumaran

First off, active state distribution is another distribution, it always follows the release from python.org. So you get the latest release from python.org too. I think, you meant the system installed python which can be bit older.

首先,活动状态分发是另一种分发,它始终遵循 python.org 的发布。所以你也可以从 python.org 获得最新版本。我想,你的意思是系统安装了可能有点旧的python。

Secondly, in your Redhat installation check if you have installed development tools and headers like gcc, glibc etc and hereare some build instructions which are given at cx_Oracle page. make sure you have followed them.

其次,在你的 Redhat 安装中,检查你是否已经安装了开发工具和头文件,如 gcc、glibc 等,这里有一些在 cx_Oracle 页面上给出的构建说明。确保您已关注他们。