Reputation: 1609
I am trying to solve an issue with PyCharm that is literally driving me crazy. I hope I will get some help here.
I am running anaconda with python 3.5 on mac os. I need to use an oracle database and I have installed the cx_Oracle package using the official instructions with "pip install". I wrote a piece of code to test the connection with the database. If I run the code from the command line, it works fine, but PyCharm does not seem to like it. The GUI seems to not find the package, as there is a red line under the import saying "No module named cx_Oracle". But I can find the module listed with the other packages in "Settings->Project->Project Interpreter". If I run it anyway, in PyCharm, I get the following error:
import cx_Oracle
ImportError: dlopen(/Users/myuser/anaconda/lib/python3.5/site-packages/cx_Oracle.cpython-35m-darwin.so, 2): Library not loaded: @rpath/libclntsh.dylib.12.1
Referenced from: /Users/myuser/anaconda/lib/python3.5/site-packages/cx_Oracle.cpython-35m-darwin.so
Reason: image not found
The project interpreter is the same as the one I am using with the command line, I have checked that with the "which" command.
sys.executable, os.getcwd() and sys.pat, are all the same in both PyCharm and from command line. The only difference seems to be in os.environ. In order to have the cx_Oracle plugin working from command line I had to set two environment variables DYLD_LIBRARY_PATH and LD_LIBRARY_PATH. If I don't set those I will get the same error with the command line too. Hence in PyCharm I have added the following lines at the beginning of my python script.
os.environ["DYLD_LIBRARY_PATH"]="/path/to/my/library"
os.environ["LD_LIBRARY_PATH"]="/path/to/my/library"
Unfortunately I still get the error if I run the code from PyCharm.
Upvotes: 1
Views: 2349
Reputation: 11
I fix similar problem by following cmd:
ln -s /opt/oracle/instantclient_12_1/libclntsh.dylib.12.1 /usr/local/lib/libclntsh.dylib.12.1
Upvotes: 1
Reputation: 7086
You need to make sure that DYLD_LIBRARY_PATH/LD_LIBRARY_PATH points to the location in which the Oracle client library (libclntsh) is found. Since PyCharm is loading it you need to make sure those environment variables are set prior to launching PyCharm itself, as they do not take effect except at process startup.
Another option is to set the environment variable FORCE_RPATH to some value prior to building cx_Oracle and installing it. This will remove the need for setting the DYLD_LIBRARY_PATH and LD_LIBRARY_PATH environment variables at runtime.
Upvotes: 0