Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python module not working in PyCharm with virtualenv

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?

like image 676
Patrick Gerrits Avatar asked Jan 29 '15 21:01

Patrick Gerrits


People also ask

How do I enable virtual env in PyCharm?

Press Ctrl+Alt+S to open the IDE settings and select Project <project name> | Python Interpreter. icon and select Show All. Select the target environment from the list and click OK to confirm your choice.

Why is my Python code not running in PyCharm?

On the main toolbar, click the run/debug configuration combobox, and make sure that 'Solver' run/debug configuration is the current one. Now you can observe results in the Run tool window.

Why PyCharm Cannot import module?

Try installing/importing a package from the system terminal (outside of PyCharm) using the same interpreter/environment. In case you are using a virtualenv/conda environment as your Project Interpreter in PyCharm, it is enough to activate that environment in the system terminal and then do the test.

Why virtualenv is not working?

Make sure that virtualenv has been installed correctly. Check in the python scripts subfolder - there must exist an .exe named virtualenv.exe . If not, uninstall will pip uninstall virtualenv and install again.


1 Answers

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

like image 174
k107 Avatar answered Oct 13 '22 09:10

k107