python module not working in PyCharm with virtualenv
Asked Answered
M

3

7

Currently i have a virtualenv created with the virtualenvwrapper. In that virtualenv i installed the cx_Oracle extension with pip install cx_Oracle.

I have a python script using several commands from cx_Oracle like connect and such.

When running my script thought the activated env (python script.py) it works fine and produces no errors.

But when i try to run the same script in PyCharm 4 it does not work. I have the virtualenv as intrepeter selected. When running the script i get an error 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 running the same script with the same command in the terminal with the env activated, i get no error.

I already tried the following: - Added ENV variables for oracle_home, etc using a script - added env variables using the pycharm env variables option

It is really annoying that i have to switch to my mac terminal for running and debugging. Has anyone a clue what could be the issue here?

Manheim answered 29/1, 2015 at 21:22 Comment(2)
Could you post a screenshot of your Python Interpreters settings for the project ? The problem is most likely there.Goddard
Probably because you referenced the wrong interpreter.Nady
D
6

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

Environment Variables

Setting variables

Derinna answered 2/4, 2015 at 21:15 Comment(0)
C
1

This is a known issue of PyCharm. The only way is to create virtualenv using PyCharm. If you create with virtualenvwrpper, there's a chance that PyCharm won't recognize it.

Cowfish answered 22/11, 2015 at 6:58 Comment(1)
btw I emailed PyCharm staff about this bug, but they say this is a bug of Python, not PyCharm, which makes me laugh because everything works fine outside PyCharm.Cowfish
M
0
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'
Macklin answered 3/1, 2016 at 9:7 Comment(1)
OSX 10.10 version of the above, the operating system environment variable settings have changed, resulting in pycharm could not be read, the temporary solution as above.Macklin

© 2022 - 2024 — McMap. All rights reserved.