我有macOS Sierra 10.12.3,我需要通过python连接到Oracle数据库。我使用pip在these instructions之后安装了cx_Oracle。在ipython中导入cx_Oracle时出现以下错误消息(Python 3.5.2 | Anaconda 4.2.0(x86_64)):
In [1]: import cx_Oracle
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-d1ecebcba3d2> in <module>()
----> 1 import cx_Oracle
ImportError: dlopen(/Users/dufoudav/anaconda/lib/python3.5/site-packages/cx_Oracle.cpython-35m-darwin.so, 2): Library not loaded: @rpath/libclntsh.dylib.12.1
Referenced from: /Users/dufoudav/anaconda/lib/python3.5/site-packages/cx_Oracle.cpython-35m-darwin.so
Reason: image not found
有关如何解决此问题的任何想法?
答案 0 :(得分:0)
instantclient-basic-macos.x64-12.1.0.2.0.zip instantclient-sdk-macos.x64-12.1.0.2.0.zip
创建目录custome convexHull
/usr/local/lib/share/oracle
复制Instant Client Basic&amp; SDK到export ORACLE_HOME=/usr/local/lib/share/oracle
export VERSION=12.1.0.2.0
export ARCH=x86_64
mkdir -p $ORACLE_HOME
/usr/local/lib/share/oracle
将两个文件解压缩到该目录:
cp instantclient-basic-macos.x64-$VERSION.zip $ORACLE_HOME
cp instantclient-sdk-macos.x64-$VERSION.zip $ORACLE_HOME
在cd $ORACLE_HOME
tar -xzf instantclient-basic-macos.x64-$VERSION.zip
tar -xzf instantclient-sdk-macos.x64-$VERSION.zip
/user/local/lib/share/oracle
现在你可以删除你不再需要的zip文件了
cd instantclient_12_1
ln -s libclntsh.dylib.12.1 libclntsh.dylib
ln -s libocci.dylib.12.1 libocci.dylib
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
移动所有文件&amp; / instantclient_12_1之外的文件夹到父目录cd /usr/local/lib/share/oracle
rm instantclient-basic-macos.x64-$VERSION.zip
rm instantclient-sdk-macos.x64-$VERSION.zip
/usr/local/lib/share/oracle
您现在应该能够安装cx_Oracle。
如果您遇到mv -v $ORACLE_HOME/instantclient_12_1/* /$ORACLE_HOME/
rm -rf instantclient_12_1/
输入终端
cx_Oracle.DatabaseError: ORA-21561: OID generation failed
复制此值并使用您喜欢的文本编辑器将其添加到hostname
文件中(在这种情况下我使用的是vi)
/etc/hosts
在其末尾有vi /etc/hosts
的行上放置一个空格并输入之前提供给您的主机名。在下面,您会看到MYMACSNAME,将该部分替换为您收到的主机名
127.0.0.1 localhost