我有Ubuntu 16.04(在Docker上),并希望使用Python连接到远程Oracle数据库。为此 - 使用cx_oracle模块。
尝试:
pip install cx_oracle
- >抱怨libaio1
和libaio-dev
遗失..
apt-get install libaio1 libaio-dev
- >再次抱怨:
cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory"
是否有一个命令可以在Ubuntu 16.04上正确安装cx_Oracle
(或者需要手动执行所有操作 - >尝试自动执行所有步骤......)
感谢。
答案 0 :(得分:0)
找不到(还)简单的方法,但这就是我所做的:
这对我来说非常适用于 Ubuntu 16 :
从Oracle下载(' 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...)
现在python脚本已经可以使用' cx_Oracle'。