Problems with PyDev and external libraries in OS X

I have successfully installed the latest version of PyDev in my Eclipse (3.5.1) under OS X 10.6.3 using python 2.6.1
I have problems creating the libraries that I installed. For example, I'm trying to use the cx_Oracle library, which works fine if called from the python interpreter from simple scripts made with some text editor.
But I can't get it to 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 run 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 

The same snippet works fine with python shell

I configured the interpreter in Eclipse in the settings -> PyDev -> Interpreter - Python, using the Auto Config option and selecting all the libraries found.

What am I doing wrong here?

Edit: launch

 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 reports the following:

 /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 
+4
source share
3 answers

In eclipse, set the following "environment variables" to "PyDev, Interpreter - Python (or which you use).

  • ORACLE_HOME = [your installation path] / instantclient_10_2
  • LD_LIBRARY_PATH = $ ORACLE_HOME
  • DYLD_LIBRARY_PATH = $ ORACLE_HOME

It worked for me.

+5
source

I don't know if you fixed it, but from the comments it looks like you have a problem with 32/64-bit versions running somewhere along the line.

cx_Oracle.so is a universal binary with PPC, 32 and 64 bit versions of Intel inside, but from your comment, your result for libclntsh.dylib.10.1 is different 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 a 32-bit client (which I store in a separate directory)

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

I assume that when starting from the command line, it either uses a different path and selects the appropriate libclntsh, or works through Eclipse, forcing it to work in the opposite mode from the command line.

Decision. Download 32-bit Instant Client versions from Oracle and 32-bit versions, but in directories with named names and manage them using links.

If you feel brave, you can perform a task that Oracle failed to do and merge the two dylibs into a universal binary.

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

I had a similar problem with cx_Oracle and Eclipse: everything worked in the terminal, same no suitable image error in Eclipse. This is definitely a binary compatibility issue (for me it was 32-bit 64-bit).

JulesLt had a solution when he linked to the developer's site. I used the lipo option described in detail in this document. It was remarkably easy. Since we have developers using 32-bit and 64-bit installations, we have already created a client-client for everyone (there are no PPC machines here).

Assuming the sibling directories for instantclient_32 , instantclient_64 and instantclient_fat -where instantclient_fat is just a copy of a 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 corresponding executables in instantclient_fat with full binary files. After you have done this, build cx_Oracle for this library instantclient and voilà.

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

0
source

Source: https://habr.com/ru/post/1310471/


All Articles