python cx_oracle module not working in PyCharm (with anaconda), but it does with command line - macos

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.

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

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.

Related

No module named 'newspaper'

I have installed "newspaper3k" both on the command line and onside the jupyter notebook. Both clearly say the package is installed. But when I sue import, it says the No Module named "newspaper".
It works on colab but not my local kernel (win 10, pyhton3).
Which python version you used while installing module and while running the code, it should be same.
Check if it is modules is present under Python{version}/lib. If not
try installing with the same python you are using try again.
If not there may be environment variable issue, set the same python version in ev

comtypes.gen attributes are different from self download and conda pre-installation

I have created my own Anaconda environment. I needed to use the 'comtypes' package to connect to the software ETABS, so I first downloaded it with the conda installation command and then I tried the next command line:
helper = comtypes.client.CreateObject('ETABSv17.Helper')
But, I received the next error:
AttributeError: module 'comtypes.gen.ETABSv17' has no attribute 'cHelper'
However, I realized that if a try the same command line with the base environment coming with Anaconda, that includes a pre-installed 'comtypes' package, there is no problem. In fact, if I check comtypes.gen.ETABSv17 with my customized environment and with the one from Conda, there is a huge difference between available attributes, even when they have the same version number: comtypes 1.1.7.
How can I get the exactly same 'comtypes' package that comes with Anaconda in order to have all the associated attributes working? Maybe, could there be some package dependence that I am missing?
Pd: I am using Windows10 and I have tried it in Pycharm and Spyder with Python 3.7
Thank you all !
I had this issue and i was using python 32 bit version. So uninstalled and installed a 64 bit version and now its working fine. May be this helps

cx_Oracle Package Not working inside Crontab

I am using cx_Oracle library in my python script. My code works fine if I directly execute by python script from Linux terminal but when I put it in crontab I am getting following error.
!!DatabaseError: DPI-1047: Oracle Client library cannot be loaded: libclntsh.so: cannot open shared object file: No such file or directory. See https://oracle.github.io/odpi/doc/installation.html for help
DPI-1005: unable to acquire Oracle environment handle
!!Traceback (most recent call last):
import cx_Oracle
!!DatabaseError: DPI-1005: unable to acquire Oracle environment handle
I googled this issue and It seems some environment variable missing when it ran using crontab.
I try to export following in crontab but it does not work.
export LD_LIBRARY_PATH='/usr/lib/oracle/11.2/client64/lib'
If I remove cx_Oracle package other code runs fine. I have only one version of python installed on my machine.
What is your version of Python? Is it 32-bit or 64-bit?
Python 2.6 . 64 bit
What is your version of cx_Oracle?
Version 6.0b1
What is your version of the Oracle client (e.g. Instant Client)? How was it
installed? Where is it installed?
oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
What is your OS and version?
CentOS 6.7
What environment variables did you set? How exactly did you set them?
export LD_LIBRARY_PATH='/usr/lib/oracle/11.2/client64/lib'
Evidently cron doesn't load the bash profile so you will need write a wrapper.
So, write a bash wrapper that exports the variables needed and calls the script. Then call that wrapper from crontab. When that works, you will know that your variables weren't being properly exported for the user whose crontab you edited.
Note: You can add them into /etc/bashrc and it will then be in place for all users, if you have root access.
You can also make a generic wrapper and cron things be sending them through the wrapper.
my_bash_wrapper.sh
#!/bin/bash
. ~/.bash_profile
"$0"
evoke in cron:
0 1 * * * /my/loc/my_bash_wrapper.sh my_python_script arg1 arg2
You should set ORACLE_HOME and LD_LIBRARY_PATH in your bash script.
#!/bin/bash
export ORACLE_HOME=/usr/lib/oracle/<version>/client(64)
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
It's not working since its looking for the oracle instant client path.
In the shell script, add the export line and point it to your oracle client path. Next, keep writing your shell script. This will work!
#!/bin/sh
export LD_LIBRARY_PATH=/home/<user_name>/opt/oracle/instantclient_19_5:$LD_LIBRARY_PATH
/usr/anaconda3/bin/python /home/<user_name>/test/src/test.py
It may work for some user
I am using Gnome Schedular to schedule python scipts.
For Normal jobs.
~anaconda3/bin/python /path_to_script/target_script.py
For Job which needs environement variable.
. ~/bash_profile ~anaconda3/bin/python /path_to_script/target_script.py

can not find ipy_user_conf.py for Enthought python

I have EPD. I would like to use the ipython shell. I think it's called 'pylab' in your distribution. I would like to be able to append to the system path ($pythonpath) at the moment when the shell loads. Unfortunately, I can not seem to locate the ipy_user_conf.py file that many users on the internet report is where I need to include a line to do that. Please help!!!
I'm going to guess that you're running IPython >= 0.11. (Note the IPython version is displayed when starting up the IPython shell.)
Older versions of IPython (pre-0.11) used ipy_user_conf.py, but IPython's configuration system was overhauled in 0.11. For details, see this overview. If you want to run some code on start up, you can add a python file in your IPython startup directory, which should be here:
~/.ipython/profile_default/startup/
Any python code in that directory gets run on startup, so you can just create a new .py to modify your python path. If the startup directory doesn't exist, you may need to run:
ipython profile create
which creates those directories (plus some other goodies).

How to set env variables when compiling Node on Windows, from Mingw32?

I'm following the instructions from various Wikis on how to compile Node so I can eventually get it running as a service on Windows.
My steps so far:
https://github.com/joyent/node/wiki/Installation
(which lead to...)
http://blog.tatham.oddie.com.au/2011/03/16/node-js-on-windows/
(successfully compiled via cygwin, but lead to...)
https://github.com/joyent/node/wiki/Building-node.js-on-mingw
(which apparently is better than the so far successful cygwin compile)
So - I've managed to compile Node.exe using Cygwin but not the preferred Mingw. I concur this isn't an ideal situation, building on Windows isn't the ideal. Nevertheless.
The error I see in Mingw, once I've followed all of the steps above, occurs when I try to ./configure --without-ssl. The error message is:
Danjah#PC /c/cygwin/home/Danjah/node-v0.4.7/node
$ ./configure –without-ssl
/usr/bin/env: python: No such file or directory
I understand from step 3's URL, that I must take steps to provide the environment variables for both Python and Git - using help from the provided URL I managed to input the Python path var, but I don't think I have the Git path var right. Either way, in no install directories for Python, Cygwin or Mingw32 do I see the path specified in the error msg: "/usr/bin/env".
Googling didn't really bring much to the table in terms of env variables or Mingw32, best I got was: PATH=C:\MinGW\bin;C:\MinGW\msys\1.0\bin where my install directory is at C:\MingW\.
The path I added to Windows environment vars for Python was: PythonPath=C:\Python27;C:\Python27\DLLs;C:\Python27\Lib;C:\Python27\Lib\lib-tk where Python 2.7 is installed in C:\Python27\.
I hate it when a file path stops you from doing things, as I suspect is the problem here. So please set me straight here - is it a file path problem I have or something else? And if its something else, please try and help me to get Node up and running... keen as to get experimenting.
I should probably also mention that I do also have a previously installed version of Git on my Windows XP SP3 machine, but had not previously had Cygwin, Mingw32 or Python installed, and I do not have IIS running as a service - my usual testing environment is a WAMP stack.
Windows uses the PATH environment variable to locate programs that are invoked without a fully qualified file path, i.e. 'python' rather than 'C:\Python27\python'.
So you need to add python's home directory to the Windows PATH variable, as well as MinGW, git and anything else your script requires.
Also by setting the PATH variable explicitly in your shell session or script, you are overwriting its original contents (in the local context) which limits which programs your shell can find to only those available within the PATH which is usually a bad idea.
See http://www.java.com/en/download/help/path.xml for details on modifying your PATH so you can always run your Python scripts from the command line.

Resources