Python和 Oracle 交互(Mac)--(cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be)

安装 cx_oracle

pip install cx_oracle

出现错误如下:

  cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "dlopen(libclntsh.dylib, 1): image not found". See https://oracle.github.io/odpi/doc/installation.html#macos for help

解决办法:

去oracle官网下载mac版的64bitclient basicclient sdk
http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html

编译安装:

sudo su 						#切换到root用户
mkdir /opt/oracle 		#创建oracle文件
mv /Users/guanguan/Downloads/instantclient-* opt/oracle
cd opt/oracle 进入oracle文件中
unzip instantclient-basic-macos.64-12.1.0.4.0.zip #解压
unzip instantclient-sdk-macos.64-12.1.0.4.0.zip #解压
cd instantclient_12_1/sdk
unzip ottclasses.zip
cd ..
cp -R ./sdk/* .
cp -R ./sdk/include .
ln -s libocci.dylib.12.1 libocci.dylib
ln -s libclntsh.dylib.12.1 libclntsh.dylib

更改环境变量:

vi ~/.bash_profile

export ORACLE_HOME=/Users/guanguan/oracle/instantclient_12_1
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME

然后输入source ~/.bash_profile 或者 . ~/.bash_profile使环境变量生效

测试环境变量是否生效

echo $ORACLE_HOME

然后解压安装cx_Oracle:

tar -zxvf cx_Oracle-5.2.1.tar.gz

cd cx_Oracle-5.2.1
python setup.py build
python setup.py install

测试cx_Oracle安装是否成功

python
import cx_Oracle

或者 python -c "import cx_Oracle"
#运行结果结果:

? ~ python Python 2.7.10 (default, Oct 23 2015, 19:19:21) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle >>>

此时说明已经安装成功啦~

报错信息:

sh-3.2# python -c "import cx_Oracle" /Library/Python/2.7/site-packages/cx_Oracle-5.2.1-py2.7-macosx-10.11-intel.egg/cx_Oracle.py:3: UserWarning: Module cx_Oracle was already imported from /Library/Python/2.7/site-packages/cx_Oracle-5.2.1-py2.7-macosx-10.11-intel.egg/cx_Oracle.pyc, but /Users/guanguan/oracle/cx_Oracle-5.2.1 is being added to sys.path Traceback (most recent call last):File "", line 1, in File "build/bdist.macosx-10.11-intel/egg/cx_Oracle.py", line 7, in File "build/bdist.macosx-10.11-intel/egg/cx_Oracle.py", line 6, in __bootstrap__ ImportError: dlopen(/var/root/.python-eggs/cx_Oracle-5.2.1-py2.7-macosx-10.11-intel.egg-tmp/cx_Oracle.so, 2): Library not loaded: @rpath/libclntsh.dylib.12.1Referenced from: /var/root/.python-eggs/cx_Oracle-5.2.1-py2.7-macosx-10.11-intel.egg-tmp/cx_Oracle.soReason: image not found

解决方法:

  1. 删除之前安装的cx_Oracl
  2. 设置export FORCE_RPATH=TRUE
  3. 重新安装cx_Oracle

批量插入数据库

oracle产生随机数字、随机字符串、随机日期

你可能感兴趣的:(linux,oracle)