cx_Oracle无法识别要在Linux上安装的Oracle软件安装位置 [英] cx_Oracle does not recognize location of Oracle software installation for installation on Linux
问题描述
我已经能够在Windows 8笔记本电脑上成功安装可与Python 3.4一起使用的cx_Oracle,现在我正尝试将相同的设置(具有Python 3.4的cx_Oracle)安装到Linux机器上。从cx_Oracle-5.1.3.tar.gz运行setup.py文件时,出现以下错误:
I have been able to successfully install cx_Oracle for use with Python 3.4 on my Windows 8 laptop, and I am now trying to get the same setup (cx_Oracle with Python 3.4) onto a Linux machine. When running the setup.py file from cx_Oracle-5.1.3.tar.gz, I end up with this error:
sudo python3 setup.py install
Traceback (most recent call last):
File "setup.py", line 135, in <module>
raise DistutilsSetupError("cannot locate an Oracle software " \
distutils.errors.DistutilsSetupError: cannot locate an Oracle software installation
在我查看了其他一些答案之后(在Windows上轻松安装cx_Oracle(Python软件包), https:// gist.github.com/jarshwah/3863378 )我已经安装了这3个即时客户端rpm:
Following some other answers I looked at (easy_install cx_Oracle (python package) on Windows, https://gist.github.com/jarshwah/3863378) I have installed these 3 instant client rpms:
rpm -ivh oracle-instantclient12.1-basic-12.1.0.2.0-1.i386.rpm
rpm -ivh oracle-instantclient12.1-devel-12.1.0.2.0-1.i386.rpm
rpm -ivh oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.i386.rpm
然后我将ORACLE_HOME设置为它们安装到的文件夹,这应该是为了帮助python识别oracle文件的位置,以便它可以执行
And then I set ORACLE_HOME to the folder that they were installed to, which is supposed to help python identify the location of the oracle files so it can do the installation properly.
每次尝试运行setup.py文件时,我仍然会收到相同的找不到Oracle软件安装错误。
I still get the same "cannot locate an Oracle software installation" error each time I try to run the setup.py file.
您知道要成功安装cx_oracle需要做些什么吗?
Any idea what I need to do to be able to successfully install cx_oracle?
更新以获取更多信息:
echo $ ORACLE_HOME返回 / instantclient_12_1
,这是安装rpm文件的位置。
echo $ORACLE_HOME returns /instantclient_12_1
, which is where the rpm files installed to.
这是我的/ instantclient_12_1目录的内容:
This is the contents of my /instantclient_12_1 directory:
adrci libnnz12.so libsqlplusic.so tnsnames.ora
BASIC_README libocci.so libsqlplus.so tnsnames.ora_andy
genezi libocci.so.12.1 ojdbc6.jar uidrvci
glogin.sql libociei.so ojdbc7.jar xstreams.jar
libclntshcore.so.12.1 libocijdbc12.so sdk
libclntsh.so libons.so sqlplus
libclntsh.so.12.1 liboramysql12.so SQLPLUS_README
这与我的Windows 8安装目录有一点不同-一个目录具有 .dll
和 .sym
文件,例如 orasql12.dll
。即时客户端安装的Linux版本是否应该具有不同的文件?
This is a bit different from the directory I have for my Windows 8 install - that one has .dll
and .sym
files, like orasql12.dll
. Should the Linux version of the instant client install have different files?
使用部分解决方案进行更新:
我找到了一个正确安装了cx_Oracle的解决方案,但仅在该shell实例中:
I found a solution that installed cx_Oracle properly, but only during that shell instance:
我设置了这两个环境变量:
I set these two environment variables:
export ORACLE_HOME=/instantclient_12_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
然后我创建了一个符号链接:
And then I created a Symbolic link:
ln -s libclntsh.so.12.1 libclntsh.so
之后,转到 cx_oracle
文件夹并执行此操作:
After that, going to the cx_oracle
folder and doing this worked:
python3 setup.py build
python3 setup.py install
由于某些原因, sudo python3 setup.py install
对此无效。
For some reason, sudo python3 setup.py install
did not work for this.
使用相关问题的链接进行更新:
我的下一个问题是获取环境变量保留在shell实例外部,因此我不必每次都定义环境变量。当我回显它们时,我放入profile.d中的环境变量会显示出来,但是python无法正确导入cx_oracle,由于某种原因,我必须再次导出环境变量。我不知道发布与问题相关的其他问题的正确过程,因此在这里打开了一个新问题:
My next problem is getting the environment variables to persist outside of the shell instance so I don't have to define the environment variables each time. The environment variables I put in profile.d show up when I echo them, but python fails to import cx_oracle properly, and I have to export the environment variables again for some reason. I don't know the proper procedure for posting a different question related to one, so I opened a new question here:
Linux profile.d环境变量不适用于Python中的cx_oracle
请帮我解决这个问题,我完全陷于尝试使之起作用的方面。当我回显它们时,会显示环境变量,但是如果我在运行python代码之前再次将其导出,则它们似乎才起作用。
Please help me out with this, I feel completely stuck on what to try to make it work. The environment variables show up when I echo them, but they only seem to be functional if I export them again before running the python code.
推荐答案
已更新
以建议使用Petriborg ,将 LD_RUN_PATH
设置为构建时间将包括在安装过程中构建的 cx_Oracle
共享库中Oracle共享库文件的路径。正如我在第一个答案中所建议的那样,这消除了对 LD_LIBRARY_PATH
的需求。
As Petriborg suggested, setting LD_RUN_PATH
at build time will include the path to the Oracle shared library files in the cx_Oracle
shared library that is built during installation. This obviates the need for LD_LIBRARY_PATH
as I suggested in my first answer.
对于您使用的RPM,应将 ORACLE_HOME
设置为 /usr/lib/oracle/12.1/client
。如果您使用的是 pip
:
For the RPMs that you are using, ORACLE_HOME
should be set to /usr/lib/oracle/12.1/client
. If you are using pip
:
$ export ORACLE_HOME=/usr/lib/oracle/12.1/client
$ export LD_RUN_PATH=/usr/lib/oracle/12.1/client/lib:$LD_RUN_PATH
$ pip install cx_Oracle
$ python -c 'import cx_Oracle; print(cx_Oracle.version)'
5.1.3
阅读此文档,以获取有关安装和执行使用客户端库的应用程序的一些信息。
Read this documentation for some info on installing and executing applications that use the client libraries.
这篇关于cx_Oracle无法识别要在Linux上安装的Oracle软件安装位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!