最近由于项目需要,需要安装cx_Oracle,我按照教程:http://joelvasallo.com/?p=276 成功安装了cx_Oracle,但是在import cx_Oracle时报错:
bogon:~ lichunyan$ python
<p style="font-size:11px;font-family:Menlo;">
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
</p>
<p style="font-size:11px;font-family:Menlo;">
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
</p>
<p style="font-size:11px;font-family:Menlo;">
Type "help", "copyright", "credits" or "license" for more information.
</p>
<p style="font-size:11px;font-family:Menlo;">
>>> import cx_Oracle
</p>
<p style="font-size:11px;font-family:Menlo;">
Traceback (most recent call last):
</p>
<p style="font-size:11px;font-family:Menlo;">
File "<stdin>", line 1, in <module>
</p>
<p style="font-size:11px;font-family:Menlo;">
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cx_Oracle.so, 2): Symbol not found: _OCIAttrGet
</p>
<p style="font-size:11px;font-family:Menlo;">
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cx_Oracle.so
</p>
<p style="font-size:11px;font-family:Menlo;">
Expected in: flat namespace
</p>
<p style="font-size:11px;font-family:Menlo;">
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cx_Oracle.so
</p>
<div>
<br>
</div>
我的Mac系统是64位的, 自己安装的python也是64位的,下载的instant client也是64位的,sdk也是64位的。。 ~/.bash_profile 文件内容如下:
Last login: Thu Apr 21 17:37:24 on console
<p style="font-size:11px;font-family:Menlo;">
bogon:~ lichunyan$ source ~/.bash_profile
</p>
<p style="font-size:11px;font-family:Menlo;">
bogon:~ lichunyan$ echo $ORACLE_HOME
</p>
<p style="font-size:11px;font-family:Menlo;">
/Users/lichunyan/oracle/instantclient_11_2
</p>
<p style="font-size:11px;font-family:Menlo;">
bogon:~ lichunyan$ vi ~/.bash_profile
</p>
<p style="font-size:11px;font-family:Menlo;">
export ORACLE_HOME=/Users/lichunyan/oracle/instantclient_11_2
</p>
<p style="font-size:11px;font-family:Menlo;">
export DYLD_LIBRARY_PATH=$ORACLE_HOME
</p>
<p style="font-size:11px;font-family:Menlo;">
export LD_LIBRARY_PATH=$ORACLE_HOME
</p>
<p style="font-size:11px;font-family:Menlo;">
export DYLD_LIBRARY_PATH
</p>
<p style="font-size:11px;font-family:Menlo;">
TNS_ADMIN=/Users/lichunyan/oracle/tns
</p>
<p style="font-size:11px;font-family:Menlo;">
export TNS_ADMIN
</p>
<p style="font-size:11px;font-family:Menlo;">
export NLS_LANG="AMERICAN_AMERICA.UTF8"
</p>
<p style="font-size:11px;font-family:Menlo;">
export LDFLAGS="-arch x86_64"
</p>
<p style="font-size:11px;font-family:Menlo;">
#
</p>
<p style="font-size:11px;font-family:Menlo;">
# Your previous /Users/lichunyan/.bash_profile file was backed up as /Users/lichunyan/.bash_profile.macports-saved_2016-04-20_at_14:15:52
</p>
<p style="font-size:11px;font-family:Menlo;">
##
</p>
<p style="font-size:11px;font-family:Menlo;">
# MacPorts Installer addition on 2016-04-20_at_14:15:52: adding an appropriate PATH variable for use with MacPorts.
</p>
<p style="font-size:11px;font-family:Menlo;">
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
</p>
<p style="font-size:11px;font-family:Menlo;">
# Finished adapting your PATH environment variable for use with MacPorts.
</p>
<p style="font-size:11px;font-family:Menlo;">
# Setting PATH for Python 2.7
</p>
<p style="font-size:11px;font-family:Menlo;">
# The orginal version is saved in .bash_profile.pysave
</p>
<p style="font-size:11px;font-family:Menlo;">
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
</p>
<p style="font-size:11px;font-family:Menlo;">
export PATH<span style="color:#5E34FF;"> </span>
</p>
<p style="font-size:11px;font-family:Menlo;">
<span style="color:#5E34FF;"><br>
有人遇到过这种问题吗?是怎么解决的呢?我已经跟这个问题纠缠了2天了,但无任何进展,愁死宝宝了
http://stackoverflow.com/questions/8158536/importing-cx-oracle-python-with-macosx楼主问题解决了吗?我也遇到了呀,我用的mac自带的python,好像无法切换到32位的python呀
我已经解决了呢,我的Mac环境其实已经是OK的了,只是我用的pycharm,这个需要另外再在其解释器里添加Oracle的那几个环境变量,添加完就OK了。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。