使用MacOSX导入cx_Oracle(python)
在python脚本中导入cx_Oracle失败 我已经安装了cx_Oracle,使用“pip install cx_Oracle”-运行良好,报告已安装 现在,当我尝试:使用MacOSX导入cx_Oracle(python),python,macos,cx-oracle,Python,Macos,Cx Oracle,在python脚本中导入cx_Oracle失败 我已经安装了cx_Oracle,使用“pip install cx_Oracle”-运行良好,报告已安装 现在,当我尝试: import cx_Oracle 我得到以下错误 Traceback (most recent call last): File "reader.py", line 9, in <module> import cx_Oracle ImportError: dlopen(/Library/Python/
import cx_Oracle
我得到以下错误
Traceback (most recent call last):
File "reader.py", line 9, in <module>
import cx_Oracle
ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): Symbol not found: _OCIAttrGet
Referenced from: /Library/Python/2.7/site-packages/cx_Oracle.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/cx_Oracle.so
甲骨文10.2
$ sqlplus -version
SQL*Plus: Release 10.2.0.4.0 - Production
此外,我的ORACLE_主文件夹中根本没有/bin目录,我只安装了即时客户端和SDK
神谕
$ pip freeze
PyRSS2Gen==1.0.0
...
cx-Oracle==5.1.1
(在安装cx_Oracle方面发现了很多问题,但没有一个问题-谢谢)卸载所有内容
然后安装oracle instant client:
- 编辑主目录中的.profile文件,并使用以下行将路径添加到oracle bin主目录:
- 导出路径=$PATH:/usr/local/lib/instantclient/
它可以工作…我今天遇到了这个问题,通过将InstantClient二进制文件中引用的库的路径更改为文件系统上的实际位置,我能够解决这个问题。 这个博客提供了详细的解释和调整所有二进制文件的脚本。唯一的问题是它使用@executable_path,这似乎不再适用于Python2.7和El Capitan(我不确定是什么导致了安全异常)。用实际路径替换@executable_path效果很好 总而言之,使其工作的步骤如下:
- 将InstantClient安装到/usr/local/InstantClient\u 11\u 2
- 确保您使用的cx_Oracle.so共享对象位于/Library/Python/2.7/site-packages/cx_Oracle.so
- 将以下脚本复制到/usr/local/instantclient_11_2
#!/bin/sh # script to change the dynamic lib paths and ids for oracle instant client # exes and libs (echo /Library/Python/2.7/site-packages/cx_Oracle.so ; find . -maxdepth 1 -type f \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print ) | while read exe do echo adjusting executable $exe baseexe=`basename $exe` otool -L $exe | awk '/oracle/ {print $1}' | while read lib do echo adjusting lib $lib baselib=`basename $lib` if [ "$baseexe" = "$baselib" ] then echo changing id to $baselib for $exe install_name_tool -id $baselib $exe else echo changing path id for $lib in $exe install_name_tool -change $lib /usr/local/instantclient_11_2/$baselib $exe fi done done
- 使用root权限运行脚本李>
#!/bin/sh
# script to change the dynamic lib paths and ids for oracle instant client
# exes and libs
(echo /Library/Python/2.7/site-packages/cx_Oracle.so ; find . -maxdepth 1 -type f \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print ) | while read exe
do
echo adjusting executable $exe
baseexe=`basename $exe`
otool -L $exe | awk '/oracle/ {print $1}' | while read lib
do
echo adjusting lib $lib
baselib=`basename $lib`
if [ "$baseexe" = "$baselib" ]
then
echo changing id to $baselib for $exe
install_name_tool -id $baselib $exe
else
echo changing path id for $lib in $exe
install_name_tool -change $lib /usr/local/instantclient_11_2/$baselib $exe
fi
done
done