为 python 安装 cx_oracle
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4307479/
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
install cx_oracle for python
提问by Mo J. Mughrabi
Am on Debian 5, I've been trying to install cx_oracle module for python without any success. First, I installed oracle-xe-client and its dependency (followed tutorial in the following link here).
在 Debian 5 上,我一直在尝试为 python 安装 cx_oracle 模块,但没有成功。首先,我安装了 oracle-xe-client 及其依赖项(遵循此处以下链接中的教程)。
Then, I used the scripts in /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/binto populate environment variables such as PATH, ORACLE_HOME and NLS_LANG.
然后,我使用/usr/lib/oracle/xe/app/oracle/product/10.2.0/client/bin 中的脚本来填充环境变量,例如 PATH、ORACLE_HOME 和 NLS_LANG。
Once, this was completed, I tried to run:
一旦完成,我尝试运行:
sudo easy_install cx_oracle
But I keep getting the following error:
但我不断收到以下错误:
Searching for cx-oracle
Reading http://pypi.python.org/simple/cx_oracle/
Reading http://cx-oracle.sourceforge.net
Reading http://starship.python.net/crew/atuining
Best match: cx-Oracle 5.0.4
Downloading http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4.tar.gz?download
Processing cx_Oracle-5.0.4.tar.gz
Running cx_Oracle-5.0.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-xsylvG/cx_Oracle-5.0.4/egg-dist-tmp-8KoqIx
error: cannot locate an Oracle software installation
Any idea what I missed here?
知道我在这里错过了什么吗?
采纳答案by tshepang
I recommend that you grab the rpm files and install them with alien. That way, you can later on run apt-get purge no-longer-needed.
我建议您获取 rpm 文件并使用 Alien 安装它们。这样,您以后就可以 run apt-get purge no-longer-needed。
In my case, the only env variable I needed is LD_LIBRARY_PATH, so I did:
就我而言,我需要的唯一环境变量是LD_LIBRARY_PATH,所以我做了:
echo export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client/lib >> ~/.bashrc
source ~/.bashrc
I suppose in your case that path variable will be /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib.
我想在你的情况下,路径变量将是/usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib.
回答by Burhan Khalid
The alternate way, that doesn't require RPMs. You need to be root.
另一种方式,不需要 RPM。你需要成为root。
Dependencies
Install the following packages:
apt-get install python-dev build-essential libaio1Download Instant Client for Linux x86-64
Download the following files from Oracle's download site:
Extract the zip files
Unzip the downloaded zip files to some directory, I'm using:
/opt/ora/Add environment variables
Create a file in
/etc/profile.d/oracle.shthat includesexport ORACLE_HOME=/opt/ora/instantclient_11_2 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOMECreate a file in
/etc/ld.so.conf.d/oracle.confthat includes/opt/ora/instantclient_11_2Execute the following command
sudo ldconfigNote: you may need to reboot to apply settings
Create a symlink
cd $ORACLE_HOME ln -s libclntsh.so.11.1 libclntsh.soInstall
cx_Oraclepython packageYou may install using
pippip install cx_OracleOr install manually
Download the cx_Oracle source zipthat corresponds with your Python and Oracle version. Then expand the archive, and run from the extracted directory:
python setup.py build python setup.py install
依赖关系
安装以下软件包:
apt-get install python-dev build-essential libaio1下载适用于 Linux x86-64 的 Instant Client
从 Oracle 的下载站点下载以下文件:
解压 zip 文件
将下载的 zip 文件解压缩到某个目录,我正在使用:
/opt/ora/添加环境变量
在
/etc/profile.d/oracle.sh其中创建一个文件export ORACLE_HOME=/opt/ora/instantclient_11_2 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME在
/etc/ld.so.conf.d/oracle.conf其中创建一个文件/opt/ora/instantclient_11_2执行以下命令
sudo ldconfig注意:您可能需要重新启动才能应用设置
创建符号链接
cd $ORACLE_HOME ln -s libclntsh.so.11.1 libclntsh.so安装
cx_Oraclepython包您可以使用安装
pippip install cx_Oracle或者手动安装
下载与您的 Python 和 Oracle 版本相对应的cx_Oracle 源 zip。然后展开存档,并从解压缩的目录中运行:
python setup.py build python setup.py install
回答by LuciusAgarthy
Thx Burhan Khalid, I overlooked your "You need to be root" quote, but found the way when you are not the root here.
Thx Burhan Khalid,我忽略了你的“你需要成为根”的名言,但是当你不是这里的根时找到了方法。
At point 7 you need to use:
在第 7 点,您需要使用:
sudo env ORACLE_HOME=$ORACLE_HOME python setup.py install
Or
或者
sudo env ORACLE_HOME=/path/to/instantclient python setup.py install
回答by TonyCoolZhu
I think it may be the sudo has no access to get ORACLE_HOME.You can do like this.
我想这可能是sudo无法获得ORACLE_HOME。你可以这样做。
sudo visudo
须藤
modify the text add
修改文本添加
Defaults env_keep += "ORACLE_HOME"
默认值 env_keep += "ORACLE_HOME"
then
然后
sudo python setup.py build install
须藤 python setup.py 构建安装
回答by user3520634
Thanks Burhan Khalid. Your advice to make a a soft link make my installation finally work.
谢谢布尔汗哈立德。您制作软链接的建议使我的安装最终成功。
To recap:
回顾一下:
You need both the basic version and the SDK version of instant client
You need to set both LD_LIBRARY_PATH and ORACLE_HOME
- You need to create a soft link (ln -s libclntsh.so.12.1 libclntsh.so in my case)
即时客户端基础版和SDK版都需要
您需要同时设置 LD_LIBRARY_PATH 和 ORACLE_HOME
- 您需要创建一个软链接(ln -s libclntsh.so.12.1 libclntsh.so 在我的情况下)
None of this is documented anywhere, which is quite unbelievable and quite frustrating. I spent over 3 hours yesterday with failed builds because I didn't know to create a soft link.
这些都没有在任何地方记录,这是非常令人难以置信和令人沮丧的。昨天我花了 3 个多小时来构建失败,因为我不知道要创建软链接。
回答by Mike Chirico
The following worked for me, both on mac and Linux. This one command should download needed additional files, without need need to set environment variables.
以下内容在 mac 和 Linux 上都对我有用。这个命令应该下载需要的额外文件,不需要设置环境变量。
python -m pip install cx_Oracle --pre
Note, the --preoption is for development and pre-release of the Oracle driver. As of this posting, it was grabbing cx_Oracle-6.0rc1.tar.gz, which was needed. (I'm using python 3.6)
请注意,-- pre选项用于开发和预发布 Oracle 驱动程序。截至发帖时,它正在抓取cx_Oracle-6.0rc1.tar.gz,这是需要的。(我正在使用 python 3.6)
回答by Zeus
Alternatively you can install the cx_Oracle module without the PIP using the following steps
或者,您可以使用以下步骤在没有 PIP 的情况下安装 cx_Oracle 模块
- Download the source from here https://pypi.python.org/pypi/cx_Oracle[cx_Oracle-6.1.tar.gz ]
Extract the tar using the following commands (Linux)
gunzip cx_Oracle-6.1.tar.gz
tar -xf cx_Oracle-6.1.tar
cd cx_Oracle-6.1Build the module
python setup.py build
Install the module
python setup.py install
- 从这里下载源https://pypi.python.org/pypi/cx_Oracle[cx_Oracle-6.1.tar.gz]
使用以下命令提取 tar (Linux)
gunzip cx_Oracle-6.1.tar.gz
tar -xf cx_Oracle-6.1.tar
cd cx_Oracle-6.1构建模块
python setup.py 构建
安装模块
python setup.py 安装
回答by Joe
This just worked for me on Ubuntu 16:
Download ('instantclient-basic-linux.x64-12.2.0.1.0.zip' and 'instantclient-sdk-linux.x64-12.2.0.1.0.zip') from Oracle web site and then do following script (you can do piece by piece and I did as a ROOT):
这只是为我工作在Ubuntu的16:
下载(“instantclient-basic-linux.x64-12.2.0.1.0.zip”和“instantclient-sdk-linux.x64-12.2.0.1.0.zip”)从甲骨文网站站点,然后执行以下脚本(您可以逐个执行,而我是作为 ROOT 执行的):
apt-get install -y python-dev build-essential libaio1
mkdir -p /opt/ora/
cd /opt/ora/
## Now put 2 ZIP files:
# ('instantclient-basic-linux.x64-12.2.0.1.0.zip' and 'instantclient-sdk-linux.x64-12.2.0.1.0.zip')
# into /opt/ora/ and unzip them -> both will be unzipped into 1 directory: /opt/ora/instantclient_12_2
rm -rf /etc/profile.d/oracle.sh
echo "export ORACLE_HOME=/opt/ora/instantclient_12_2" >> /etc/profile.d/oracle.sh
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME" >> /etc/profile.d/oracle.sh
chmod 777 /etc/profile.d/oracle.sh
source /etc/profile.d/oracle.sh
env | grep -i ora # This will check current ENVIRONMENT settings for Oracle
rm -rf /etc/ld.so.conf.d/oracle.conf
echo "/opt/ora/instantclient_12_2" >> /etc/ld.so.conf.d/oracle.conf
ldconfig
cd $ORACLE_HOME
ls -lrth libclntsh* # This will show which version of 'libclntsh' you have... --> needed for following line:
ln -s libclntsh.so.12.1 libclntsh.so
pip install cx_Oracle # Maybe not needed but I did it anyway (only pip install cx_Oracle without above steps did not work for me...)
Your python scripts are now ready to use 'cx_Oracle'... Enjoy!
您的 Python 脚本现在可以使用“cx_Oracle”了……尽情享受吧!
回答by vikash prasad
If you are trying to install in MAC , just unzip the Oracle client which you downloaded and place it into the folder where you written python scripts. it will start working.
如果您尝试在 MAC 中安装,只需解压缩您下载的 Oracle 客户端并将其放入您编写 python 脚本的文件夹中。它将开始工作。
There is too much problem of setting up environmental variables. It worked for me.
设置环境变量问题太多。它对我有用。
Hope this helps.
希望这可以帮助。
Thanks
谢谢
回答by Sateesh
This worked for me
这对我有用
python -m pip install cx_Oracle --upgrade
For details refer to the oracle quick start guide
详情参考oracle快速入门指南
https://cx-oracle.readthedocs.io/en/latest/installation.html#quick-start-cx-oracle-installation
https://cx-oracle.readthedocs.io/en/latest/installation.html#quick-start-cx-oracle-installation


