I try to write a script in .py for oracle connectivity:
#!/usr/bin/python
import cx_Oracle
connstr=\'username/pwd@database\'
conn = cx_Oracle.connect(conns
Windows help:
Go to the command prompt (Win+R and type cmd
) and set 2 variables matching your location- for example:
set TNS_ADMIN=C:\instant_client\instantclient_11_2
set ORACLE_HOME=C:\instant_client\instantclient_11_2
Then install the cx_Oracle module from an exe. If you use pip or easy_install, ...good luck.
You can get the installer here: https://pypi.python.org/pypi/cx_Oracle/5.1.3
Tried installing it via rpm posted in above answers, but it didn't worked. What worked instead is plain pip install
.
pip install cx_oracle
The above command installed cx_oracle=6.1
Please note that I'm using python 2.7.14 Anaconda release
and oracle 12c
.
Windows and Anaconda help
Anaconda 4.3.0 comes with Python 3.6 as the root. Currently cx_Oracle only supports up to 3.5. I tried creating 3.5 environment in envs, but when running cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe it installs in root only against 3.6
Only workaround I could find was to change the root environment from 3.6 to 3.5:
activate root
conda update --all python=3.5
When that completes run cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe.
Tested it with import and worked fine.
import CX_Oracle
I had a similar problem, you gotta make sure you have:
To access Oracle from python you need (additionally) the cx_Oracle module. The module must be located either in the system python path or you have to set the PYTHONPATH appropriate.
Unknown92 answer helped me (on windows). Note that all versions must fit.
I've downloaded cx_Oracle here, for me the file cx_Oracle-5.2.1-12c.win-amd64-py3.5.exe worked with: