The python module does not work in PyCharm with virtualenv

I currently have virtualenv created using virtualenvwrapper. In this virtualenv, I installed the cx_Oracle extension with pip install cx_Oracle.

I have a python script using several commands from cx_Oracle such as connect, etc.

When you run my script, it is considered activated env (python script.py), it works fine and does not produce errors.

But when I try to run the same script in PyCharm 4, it does not work. I have virtualenv as the selected intrepeter. When I run the script, I get an error message as follows:

/Users/pgerrits/.virtualenvs/siebelaudit/bin/python3.4 -u /Applications/PyCharm.app/Contents/helpers/pydev/pydev_run_in_console.py 64420 64421 /Users/pgerrits/PycharmProjects/SiebelAudit/Audit/Siebel Audit/scratchpad.py Running /Users/pgerrits/PycharmProjects/SiebelAudit/Audit/Siebel Audit/scratchpad.py PyDev console: starting. ImportError: dlopen(/Users/pgerrits/.virtualenvs/siebelaudit/lib/python3.4/site-packages/cx_Oracle.so, 2): Library not loaded: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1 Referenced from: /Users/pgerrits/.virtualenvs/siebelaudit/lib/python3.4/site-packages/cx_Oracle.so Reason: image not found 

When I run a script with the same command in a terminal with env enabled, I do not get an error.

I already tried the following: - Added ENV variables for oracle_home, etc. Using script - added env variables using pyvarm env variable options

It's really annoying that I have to switch to my terminal for Mac and debugging. Anyone tell me what could be the problem here?

+8
python virtualenv pycharm virtualenvwrapper cx-oracle
source share
3 answers

I had to set environment variables for ORACLE_HOME DYLD_LIBRARY_PATH and LD_LIBRARY_PATH and restart PyCharm to get cx_Oracle working.

Environment Variables

Setting variables

+6
source share

This is a known PyCharm issue. The only way is to create virtualenv using PyCharm. If you create using virtualenvwrpper, chances are that PyCharm will not recognize it.

+1
source share
 import os import platform if platform.system() == 'Darwin': os.environ["ORACLE_HOME"] = '/opt/oracle/instantclient_11_2' os.environ["DYLD_LIBRARY_PATH"] = '/opt/oracle/instantclient_11_2' os.environ["LD_LIBRARY_PATH"] = '/opt/oracle/instantclient_11_2' 
0
source share

All Articles