OS X 中 PyDev 和外部库的问题

发布于 2024-09-02 02:10:37 字数 1944 浏览 4 评论 0原文

我已在 OS X 10.6.3 下的 Eclipse (3.5.1) 中成功安装了最新版本的 PyDev,使用 python 2.6.1
我在使已安装的库正常工作时遇到了麻烦。
例如,我正在尝试使用 cx_Oracle 库,如果从使用某些文本编辑器制作的简单脚本的 python 解释器调用,该库可以完美工作。
但我无法让它在 Eclipse 中工作:我有一小段代码:

import cx_Oracle
conn = cx_Oracle.connect(CONN_STRING)
sql = "select field from mytable"
cursor = conn.cursor()
cursor.execute(sql)
for row in cursor:
    field = row[0]
    print field

如果我从 Eclipse 执行它,我会收到以下错误:

import cx_Oracle
  File "build/bdist.macosx-10.6-universal/egg/cx_Oracle.py", line 7, in <module>
  File "build/bdist.macosx-10.6-universal/egg/cx_Oracle.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so, 2): Library not loaded: /b/227/rdbms/lib/libclntsh.dylib.10.1
  Referenced from: /Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so
  Reason: no suitable image found.  Did find:
    /Users/dave/lib/libclntsh.dylib.10.1: mach-o, but wrong architecture

相同的代码片段在 python shell 中完美运行

我已经在 Eclipse 中的首选项 -> 中配置了解释器PyDev -->解释器 - Python,使用“自动配置”选项并选择找到的所有库。

我在这里做错了什么?

编辑:

file /Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so

从命令行启动告诉我们:

/Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so: Mach-O universal binary with 3 architectures
/Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so (for architecture i386):  Mach-O bundle i386
/Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so (for architecture ppc7400):   Mach-O bundle ppc
/Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so (for architecture x86_64):    Mach-O 64-bit bundle x86_64

I've successfully installed the latest version of PyDev in my Eclipse (3.5.1) under OS X 10.6.3, with python 2.6.1
I have troubles in making the libraries I have installed work.
For example, I'm trying to use the cx_Oracle library, which is perfectly working if called from the python interpeter of from simple scripts made with some text editor.
But I cant make it work inside Eclipse: I have this small piece of code:

import cx_Oracle
conn = cx_Oracle.connect(CONN_STRING)
sql = "select field from mytable"
cursor = conn.cursor()
cursor.execute(sql)
for row in cursor:
    field = row[0]
    print field

If I execute it from Eclipse, I get the following error:

import cx_Oracle
  File "build/bdist.macosx-10.6-universal/egg/cx_Oracle.py", line 7, in <module>
  File "build/bdist.macosx-10.6-universal/egg/cx_Oracle.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so, 2): Library not loaded: /b/227/rdbms/lib/libclntsh.dylib.10.1
  Referenced from: /Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so
  Reason: no suitable image found.  Did find:
    /Users/dave/lib/libclntsh.dylib.10.1: mach-o, but wrong architecture

Same snippet works perfectly from the python shell

I have configured the interpeter in Eclipse in preferences -> PyDev --> Interpreter - Python, using the Auto Config option and selecting all the libs found.

What am I doing wrong here?

Edit: launching

file /Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so

from the command line tells this:

/Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so: Mach-O universal binary with 3 architectures
/Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so (for architecture i386):  Mach-O bundle i386
/Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so (for architecture ppc7400):   Mach-O bundle ppc
/Users/dave/.python-eggs/cx_Oracle-5.0.3-py2.6-macosx-10.6-universal.egg-tmp/cx_Oracle.so (for architecture x86_64):    Mach-O 64-bit bundle x86_64

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

2024-09-09 02:10:37

在 Eclipse 中,在“PyDev”、解释器 – Python(或您正在使用的任何一个)下设置以下“环境变量”。

  1. ORACLE_HOME=[您的安装路径]/instantclient_10_2
  2. LD_LIBRARY_PATH=$ORACLE_HOME
  3. DYLD_LIBRARY_PATH=$ORACLE_HOME

它对我有用。

In eclipse, set the following ‘environment variables’ under ‘PyDev’, Interpreter – Python (or which ever you are using).

  1. ORACLE_HOME=[your installation path]/instantclient_10_2
  2. LD_LIBRARY_PATH=$ORACLE_HOME
  3. DYLD_LIBRARY_PATH=$ORACLE_HOME

It worked for me.

丑丑阿 2024-09-09 02:10:37

不知道您是否已修复此问题,但从评论来看,您似乎在某个地方遇到了 32 / 64 位问题。

cx_Oracle.so 是一个通用二进制文件,内部有 PPC、32 位和 64 位 Intel 版本,但从您的评论来看,您的 libclntsh.dylib.10.1 的结果与我的不同,

file libclntsh.dylib.10.1
libclntsh.dylib.10.1: Mach-O 64-bit dynamically linked shared library x86_64

而如果我对 32 位运行相同的命令,我会得到与您相同的结果位客户端(我将其保存在单独的目录中)

file libclntsh.dylib.10.1
libclntsh.dylib.10.1: Mach-O dynamically linked shared library i386

我猜测,当从命令行运行时,它要么使用不同的路径并选择适当的 libclntsh,要么通过 Eclipse 运行导致它以相反的模式运行命令行。

解决方案 - 从 Oracle 下载 32 位和 64 位版本的 Instant Client,但位于不同的命名目录中,并通过使用链接控制使用哪一个版本。

如果您有勇气,您可以完成 Oracle 未能完成的工作,并将两个 dylib 合并为通用二进制文件。

http://developer.apple.com/mac/library/technotes/tn2005/tn2137.html#TNTAG3

Don't know if you have fixed this yet, but from the comments it looks like you have a 32 / 64 bit issue going on somewhere along the line.

cx_Oracle.so is a universal binary with PPC, 32 and 64 bit Intel versions inside, but from your comment your result for libclntsh.dylib.10.1 differs from mine

file libclntsh.dylib.10.1
libclntsh.dylib.10.1: Mach-O 64-bit dynamically linked shared library x86_64

while I get the same result as you if I run the same command against the 32 bit client (which I keep in a separate directory)

file libclntsh.dylib.10.1
libclntsh.dylib.10.1: Mach-O dynamically linked shared library i386

I am guessing that when running from the command line it is either using a different path and picking up the appropriate libclntsh, or that running through Eclipse is causing it to run in the opposite mode from command line.

Solution - download both 32 and 64 bit versions of Instant Client from Oracle, but in differently named directories, and control which one is used by using links.

If you are feeling brave, you could do the job Oracle failed to do and merge the two dylib into a Universal binary.

http://developer.apple.com/mac/library/technotes/tn2005/tn2137.html#TNTAG3
余生共白头 2024-09-09 02:10:37

我在使用 cx_Oracle 和 Eclipse 时遇到了类似的问题:终端中一切正常,Eclipse 中同样没有合适的图像错误。这绝对是一个二进制兼容性问题(对我来说,是 32 位与 64 位)。

JulesLt 在引用开发者网站时找到了解决方案。我使用了该文档中详细介绍的 lipo 选项。这非常容易。由于我们的开发人员同时使用 32 位和 64 位安装,因此我们已经为每种安装构建了一个即时客户端(这里没有 PPC 机器)。

假设 instantclient_32instantclient_64instantclient_fat 的同级目录 — 其中 instantclient_fat 只是 32-或 64 位目录 - 以下应该可以解决问题:

cd instantclient_32 ; for f in `ls *dylib* genezi sqlplus` ; do lipo -create $f ../instantclient_64/$f -output ../instantclient_fat/$f ; done

上面的代码将使用 fat 二进制文件覆盖 instantclient_fat 中的相关可执行文件。完成此操作后,针对此 instantclient 库构建 cx_Oracle 即可。

感谢 JulesLt ...这解决了许多烦人的问题。

I had a similar issue with cx_Oracle and Eclipse: Everything worked in Terminal, same no suitable image error in Eclipse. This was definitely an binary compatibility issue (for me, it was 32- vs 64-bit).

JulesLt had the solution when he referenced the developer site. I used the lipo option detailed in that document. It was remarkably easy. As we have developers using both 32-bit and 64-bit installations, we already had an instantclient built for each (no PPC machines here).

Assuming the sibling directories of instantclient_32, instantclient_64 and instantclient_fat —where instantclient_fat is just a copy of either the 32- or 64-bit directory—the following should do the trick:

cd instantclient_32 ; for f in `ls *dylib* genezi sqlplus` ; do lipo -create $f ../instantclient_64/$f -output ../instantclient_fat/$f ; done

The above will overwrite the relevant executables in instantclient_fat with the fat binaries. Once you have done this, build cx_Oracle against this instantclient library and voilà.

Thanks to JulesLt ... this solved a number of annoying issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文