macos 无法让 cx_Oracle 与 Python 2.7 版/mac os 10.7.2 (Lion) 一起使用 - missing_OCIAttrGet
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8169946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't get cx_Oracle to work with Python version 2.7 / mac os 10.7.2 (Lion) - missing_OCIAttrGet
提问by nycynik
Can't get cx_Oracle to work with Python version 2.7 / mac os 10.7.2 (Lion)
无法让 cx_Oracle 与 Python 2.7 / mac os 10.7.2 (Lion) 一起使用
One other thing: I have installed oracle 32 bit, not sure if that was correct.
另一件事:我安装了 oracle 32 位,不确定这是否正确。
Traceback (most recent call last):
File "reader.py", line 9, in <module>
import cx_Oracle
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 7, in <module>
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so, 2): Symbol not found: _OCIAttrGet
Referenced from: /Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so
Expected in: flat namespace
in /Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so
They key problem seems to be not being able to locate _OCIAttGet
, and I think this means that it cant find a lib file or something.
他们的关键问题似乎是无法定位_OCIAttGet
,我认为这意味着它无法找到 lib 文件或其他东西。
Found on the web, someone talking about DYLD_LIBRARY_PATH
, but mine is set, however he mentioned it in cxoracle.cfg
file, that I can not locate, is this my problem?
在网上找到,有人在谈论DYLD_LIBRARY_PATH
,但我的已设置,但他在cxoracle.cfg
文件中提到了,我找不到,这是我的问题吗?
EDIT
编辑
After trying to run it with 32 bit mode python, I see a different error.
在尝试使用 32 位模式 python 运行它后,我看到了一个不同的错误。
Traceback (most recent call last):
File "reader.py", line 9, in <module>
import cx_Oracle
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 7, in <module>
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 3, in __bootstrap__
ImportError: No module named pkg_resources
- I could not get the oracle 64 bit versions to run on my computer, kept getting segmentation faults when i ran sqlplus, so thats why I am using the 32.
- 我无法在我的计算机上运行 oracle 64 位版本,当我运行 sqlplus 时不断出现分段错误,所以这就是我使用 32 的原因。
SECOND EDIT
第二次编辑
Actually no matter what i install, it is not the right version.. 32 bit version
实际上无论我安装什么,它都不是正确的版本.. 32 位版本
ld: warning: ignoring file /opt/oracle/instantclient10_2/libclntsh.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
64 bit version:
64位版本:
ld: warning: ignoring file /opt/oracle/instantclient10_2/libclntsh.dylib, file was built for unsupported file format which is not the architecture being linked (x86_64)
I am going to try 11g, but that only has a 64 bit version.
我将尝试 11g,但它只有 64 位版本。
采纳答案by Ned Deily
If you are using the Apple-supplied Python 2.7, it will prefer to run in 64-bit mode and that will be a problem if you did install 32-bit-only Oracle libraries. You can try forcing that Python to run in 32-bit mode by starting it this way:
如果您使用 Apple 提供的 Python 2.7,它将更喜欢在 64 位模式下运行,如果您安装了仅 32 位的 Oracle 库,这将是一个问题。您可以尝试通过以下方式启动 Python 以强制其在 32 位模式下运行:
arch -i386 python2.7
If you are careful to always launch python via /usr/bin/python
, you could also use either of the methods described in Apple's man
page for Python, i.e. setting a VERSIONER_PYTHON_PREFER_32_BIT
environment variable or setting a permanent default via defaults
.
如果您总是小心地通过 启动 python /usr/bin/python
,您还可以使用 Apple 的man
Python 页面中描述的任何一种方法,即设置VERSIONER_PYTHON_PREFER_32_BIT
环境变量或通过 设置永久默认值defaults
。
回答by user1177140
To compile cx_Oracle so it'll work on OS Xneeds a couple of things configured. The important bits are:
要编译 cx_Oracle 使其在 OS X 上工作,需要配置一些东西。重要的位是:
Create a virtualenv with a python interpreter stripped to 32-bit only. In the virtualenv bin directory (
$WORKON_HOME/*name_of_virtualenv*/bin
):% mv python python.fat % lipo python.fat -remove x86_64 -output python
Even though Python is now thin its configuration is not so we need to force things using an obscure environment variable that distutils will pick up:
ARCHFLAGS="-arch i386" pip install cx_Oracle
使用仅被剥离为 32 位的 python 解释器创建一个 virtualenv。在 virtualenv bin 目录 (
$WORKON_HOME/*name_of_virtualenv*/bin
) 中:% mv python python.fat % lipo python.fat -remove x86_64 -output python
尽管 Python 现在很瘦,但它的配置不是这样,所以我们需要使用 distutils 将获取的模糊环境变量强制执行:
ARCHFLAGS="-arch i386" pip install cx_Oracle
回答by chadmaughan
Not certain if you're still having problems with this, but here is how I got it to work.
不确定您是否仍然遇到问题,但这是我让它工作的方式。
I followed the instructions listed here (using the 32-bit downloads from Oracle): http://www.xairon.net/2011/05/guide-installing-cx_oracle-on-mac-os-x/
我按照此处列出的说明进行操作(使用 Oracle 的 32 位下载):http: //www.xairon.net/2011/05/guide-installing-cx_oracle-on-mac-os-x/
I then had the same error you listed:
然后我遇到了您列出的相同错误:
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
导入错误:dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2):找不到符号:_OCIAttrGet 引用自:/Library/Python/2.7/site-packages/cx_Oracle.so 预期在:平面命名空间中/Library/Python/2.7/site-packages/cx_Oracle.so
The problem was from Apple's Python distribution running in 64-bit mode by default.
问题出在默认情况下以 64 位模式运行的 Apple 的 Python 发行版。
Once I forced the Apple supplied Python to use 32-bit (from Ned's recommendation), it worked!
一旦我强迫 Apple 提供的 Python 使用 32 位(来自 Ned 的推荐),它就起作用了!
To do that:
要做到这一点:
$export VERSIONER_PYTHON_PREFER_32_BIT=Yes
$export VERSIONER_PYTHON_PREFER_32_BIT=是
To make it permanent:
要使其永久化:
$defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
$defaults 写 com.apple.versioner.python Prefer-32-Bit -bool 是
回答by Kris
Steps to install to oracle client on mac ox 10.8.5 for connecting oracle from python. (There is bug due to it 64 bit doesn't work for mac ox 10.8.5 )
在 mac ox 10.8.5 上安装到 oracle 客户端以从 python 连接 oracle 的步骤。(有一个错误,因为它 64 位不适用于 mac ox 10.8.5 )
- Go to http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
- Download instantclient-basic-macos.x32-11.2.0.3.0.zip
- Download instantclient-sdk-macos.x32-11.2.0.3.0.zip
- Create new folder under /Users/< your username>/ora_32(you can name what you want )
Move the zip files instantclient-sdk-macos.x32-11.2.0.3.0.zip and instantclient-basic-macos.x32-11.2.0.3.0.zip to /Users/< your username>/ora_32 Command below
mv insta*32* /Users/< your username>/ora_32/
Unzip instantclient-basic-macos.x32-11.2.0.3.0.zip and instantclient-sdk-macos.x32-11.2.0.3.0.zip Command below
cd /Users/< your username>/ora_32/ unzip instantclient-basic-macos.x32-11.2.0.3.0.zip unzip instantclient-sdk-macos.x32-11.2.0.3.0.zip
- it will create a folder instantclient_11_2 under /Users//ora_32/
cd to /Users/< your username>/ora_32/instantclient_11_2 and Create the below symbolic link which will be used in the installation of cx_Oracle.( Mentioned below )
ln -s libclntsh.dylib.11.1 libclntsh.dylib ln -s libocci.dylib.11.1 libocci.dylib
Export the environment variables for the current session or you can add them in bash profile to invoke every time you open a new terminal.
export ORACLE_HOME=/Users/<your username>/ora_32/instantclient_11_2 export LD_LIBRARY_PATH=$ORACLE_HOME export DYLD_LIBRARY_PATH=$ORACLE_HOME export VERSIONER_PYTHON_PREFER_32_BIT=yes export PATH=$PATH:/Users/<your username>/ora_32/instantclient_11_2
- Download cx_Oracle (option source code only) at the link http://cx-oracle.sourceforge.net
- Untar the cx_Oracle tar file and it will create a cx_Oracle-5.1.2 folder cd to that folder cx_Oracle-5.1.2
Run the below command it will install cx_Oracle and then
sudo easy_install cx_Oracle
- You can check by going to python prompt and typing import cx_Oracle
- 转至http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
- 下载instantclient-basic-macos.x32-11.2.0.3.0.zip
- 下载instantclient-sdk-macos.x32-11.2.0.3.0.zip
- 在 /Users/< 你的用户名>/ora_32 下创建新文件夹(你可以命名你想要的)
将zip文件instantclient-sdk-macos.x32-11.2.0.3.0.zip和instantclient-basic-macos.x32-11.2.0.3.0.zip移动到/Users/<您的用户名>/ora_32下面的命令
mv insta*32* /Users/< your username>/ora_32/
解压instantclient-basic-macos.x32-11.2.0.3.0.zip和instantclient-sdk-macos.x32-11.2.0.3.0.zip下面的命令
cd /Users/< your username>/ora_32/ unzip instantclient-basic-macos.x32-11.2.0.3.0.zip unzip instantclient-sdk-macos.x32-11.2.0.3.0.zip
- 它将在 /Users//ora_32/ 下创建一个文件夹 Instantclient_11_2
cd 到 /Users/<您的用户名>/ora_32/instantclient_11_2 并创建以下符号链接,该链接将用于安装 cx_Oracle。(下面提到)
ln -s libclntsh.dylib.11.1 libclntsh.dylib ln -s libocci.dylib.11.1 libocci.dylib
导出当前会话的环境变量,或者您可以将它们添加到 bash 配置文件中以在每次打开新终端时调用。
export ORACLE_HOME=/Users/<your username>/ora_32/instantclient_11_2 export LD_LIBRARY_PATH=$ORACLE_HOME export DYLD_LIBRARY_PATH=$ORACLE_HOME export VERSIONER_PYTHON_PREFER_32_BIT=yes export PATH=$PATH:/Users/<your username>/ora_32/instantclient_11_2
- 在链接http://cx-oracle.sourceforge.net下载 cx_Oracle(仅选项源代码)
- 解压 cx_Oracle tar 文件,它将创建一个 cx_Oracle-5.1.2 文件夹 cd 到该文件夹 cx_Oracle-5.1.2
运行以下命令,它将安装 cx_Oracle 然后
sudo easy_install cx_Oracle
- 您可以通过转到 python 提示符并键入 import cx_Oracle 来检查
回答by jatal
I had this same problem. I'm using Mac OS X 10.8.3.
我有同样的问题。我使用的是 Mac OS X 10.8.3。
After 4 hours of trying various solutions, I finally realized that this was the result of having installed the 32-bit version of Oracle InstantClient, which conflicted with the 64-bit version of python.
尝试了4个小时的各种解决方案,终于意识到这是安装了32位版本的Oracle InstantClient与64位版本的python冲突的结果。
To resolve: I uninstalled python (and some dependencies), then reinstalled the universal version. I followed the directions in this post to strip the x86_64 from the python binary in my virtualenv. This allowed the 32-bit Oracle InstantClient to work with the 32-bit python binary.
解决方法:我卸载了 python(和一些依赖项),然后重新安装了通用版本。我按照这篇文章中的说明从我的 virtualenv 中的 python 二进制文件中剥离了 x86_64。这允许 32 位 Oracle InstantClient 使用 32 位 python 二进制文件。
I am hesitant to use the 64-bit Oracle InstantClient, due to some other posts I saw while researching this issue.
由于我在研究此问题时看到的其他一些帖子,我对使用 64 位 Oracle InstantClient 犹豫不决。