cx_Oracle ImportError Reason: image not found

354 views Asked by At

When trying to run a script that uses cx_Oracle I'm getting an ImportError.

./runtests.py <args here>

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/smeatonj/Development/.virtualenvs/djangopy3/lib/python3.5/site-packages/cx_Oracle.cpython-35m-darwin.so, 2): Library not loaded: @rpath/libclntsh.dylib.12.1
  Referenced from: /Users/smeatonj/Development/.virtualenvs/djangopy3/lib/python3.5/site-packages/cx_Oracle.cpython-35m-darwin.so
  Reason: image not found

Advice elsewhere suggests exporting LD_LIBRARY_PATH which I've done. When I open a python shell and try to import cx_Oracle it works fine.

1

There are 1 answers

0
Josh Smeaton On

The problem was that the script was prefixed with:

#!/usr/bin/env python
import cx_Oracle

I think this prevents the shell from using LD_LIBRARY_PATH. The fix is to execute the script with python directly:

python runtests.py

I'd be happy to edit this answer with additional information on LD_LIBRARY_PATH if someone knows more.