I am using cx_Oracle to access the Oracle database for some time and it works fine. Now my co-worker wants to run my scripts and we run across a problem with cx_Oracle. Wile trying to connect to the database we got the error: InterfaceError: Unable to acquire Oracle environment handle.
I read on a stackoverflow post that the probable error is that there are multiple oci.dll files found on the path. In our case we have two instant clients installed,I installed instant client 12 and there is another, very old installed from before that is used by some other applications. How can I tell Python which instant client to use?
She is using Windows XP and I installed her instant client 12, python 3.4 and cx_oracle 5.2, all 32 bit.
You need to ensure the PATH and ORACLE_HOME environment variables are pointing to the same Oracle client install. In the case of PATH (which you imply may contain multiple Oracle client installations), you need to ensure the one you wish to use appears first.
Instead of relying on system-wide settings for these environment variables, you may want to wrap your Python script in a batch file that ensures these variables are set correctly before starting the interpreter. For example, assuming you installed the Oracle 12.1 instant client to C:\Oracle\instantclient_12_1:
#ECHO OFF
SET ORACLE_HOME=C:\Oracle\instantclient_12_1
SET PATH=C:\Oracle\instantclient_12_1;%PATH%
python path_to_my_script.py
Related
i am trying to connect my oracle 11g database to django but it didn't connect it show some error like
return Database.connect(
django.db.utils.DatabaseError: DPI-1047: Cannot locate a 32-bit Oracle Client library: "C:\oraclexe\app\oracle\product\11.2.0\server\bin\oci.dll is not the correct architecture". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
i sucessfully install 32 bit oracle client library but it still shows same error.
i am new to django and this error pops up when i use command python manage.py makemigrations it didn't create migration instead it shows this error.
it would be pleasure if someone helps me.
thankyou :)
The error is because you have a 64-bit Oracle Database installed, and its libraries are first in PATH so Python cx_Oracle tries to load them. Unfortunately your Python is 32-bit so there is a clash, which is shown by the error.
You choices are to set PATH to have your 32-bit Oracle client libraries first when you run Python. You probably don't want to do this globally since that might affect other Oracle DB tools, so you would need to do it in a cmd terminal, or set up a script that sets PATH and then calls python. You would call your new script anytime you wanted to run Python.
Overall, it's probably easier to uninstall Python, and install a 64-bit Python.
I am unable to connect to our enterprise Oracle Db using python 3/cx_Oracle.
Installed are:
python 3 -32 bit
cx_Oracle
Oracle Client 12.1.0.2.0
My connection string attempt is:
import cx_Oracle
conn = cx_Oracle.connect(user='user', password='pwd', dsn='working_dsn')
My PATH variable includes the direct path to my working Oracle library (works using SQL Dev
Error message is:
cx_Oracle.DatabaseError: DPI-1050: Oracle Client library is at version 0.0 but must be at version 11.2 or higher
I have researched the Orcale installation instructions and have found no way to connect. I have previously tried with no success, had my computer reimaged and Oracle reinstalled to ensure only one version of Oracle and still no success. I need to move from R to Python and this is the last piece I need to make the switch. I am able to connect with R using JDBC driverclass/dbConnect.
If cx_Oracle wont work, is there another option for connecting to Oracle from Python3?
Any thoughts suggestions or places to look? Other connection types used?
Thanks in advance.
pip3 install cx_Oracle
first method:
db = cx_Oracle.connect('root/root#localhost: 1523/orcl')
Second method:
db = cx_Oracle.connect('root/root#localhost: 1523/orcl')
Third method
makedsn(IP/HOST, PORT, TNSNAME)
dsn = cx_Oracle.makedsn('localhost','1523','orcl')
db = cx_Oracle.connect('root','root',dsn)
The error you are getting suggests that you have an older version of the Oracle client installed on your machine. Search the directories of your PATH environment variable for OCI.DLL. If you find an older version you'll need to remove or rename it -- just be aware that whatever application put the file there will stop working!
Another possibility is to go to a command prompt and do the following
PATH=my_path_to_instant_client;%PATH%
python test_connect.py
Finally, make sure that if your Python is 32-bit, so is your instant client installation, and if your Python is 64-bit, make sure that your instant client installation is also 64-bit.
I created an exe of my program that communicates with an oracle database using cx_Oracle to create excel sheets. If someone else uses this exe will they need Oracle installed?
Any computer that runs Python programs using cx_Oracle will need an 'Oracle client' installed. This is the set of Oracle libraries needed by cx_Oracle that allow connections to a database. The database can be on a remote computer. The Oracle client libraries are available in three different installs:
With the Oracle Database install
With a 'full' Oracle Client install
From Oracle Instant Client
The most common in your case would be to use Oracle Instant Client, which is relatively small and is simple to install.
You download the Instant Client 'Basic' package matching your operating system and the Python architecture (32 or 64 bit). Unzip it. Set your operating system search path such as PATH (on Windows) or LD_LIBRARY_PATH or ldconfig (on Linux) to the directory you unzipped.
Instant Client Downloads and instructions are at https://www.oracle.com/database/technologies/instant-client.html
cx_Oracle installation instructions are at https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html
I want to learn how to work with an Oracle Database using Python. If I understand correctly, you can use Oracle Instant Client to connect to an Oracle Database remotely, but I cannot connect. I suspect the issue is that I don't know what arguments to use for the localhost/instance combo. I believe localhost is simply my machine name, or it may be literally 'localhost' which I have tried, but I don't know how and can't find help to tell me how to locate the service name for the database instance.
In a prompt I opened python, imported cx_Oracle and used 'Easy Connect String' as specified in this sample code, using either "(my machine name)/orclpdb" or literally "localhost/orclpdb" for DEFAULT_CONNECT_STRING.
The sample code creates a variable MAIN_CONNECT_STRING which I used in a command prompt to attempt to connect to the remote database:
cnxn = cx_Oracle.connect(MAIN_CONNECT_STRING)
cx_Oracle.DatabaseError: ORA-12541: TNS:no listener
I find answers that seem to be based on this, or others referring to tnsnames.ora, or listener.ora which are files I don't have. I also tried using instantclient-sqlplus-nt-12.2.0.1.0.
Background:
Windows 7
I downloaded cx_Oracle-6.1-cp27-cp27m-win32.whl and
instantclient-basic-nt-12.2.0.1.0.zip
I put the .whl into "C:\Python27\Scripts\"
I used python -m pip
install cx_Oracle --upgrade to install cx_Oracle.
I unzipped the instant client zip and put the child folder here
"C:\instantclient_12_2"
I added ;C:\instantclient_12_2 to the end of PATH.
Maybe you can use the installation instructions found in the
cx_Oracle documentation for Windows, cx_Oracle for Windows
Uninstall first the cx_Oracle you are using then try to follow the instructions found in the link above.
I had a look at cx_Oracle but I have a couple of problems with it. First , my oracle server is on remote machine. Second I do not know on what platform my software will be deployed. All the examples I have founded
like this
http://www.len.ro/2009/08/cx_oracle-on-ubuntu-9-04-jaunty/
or
this https://stackoverflow.com/questions/592/cx-oracle-how-do-i-access-oracle-from-python
assume to have oracle server on the same machine. Is there possibility to have some static compilation so I can easily move my software from one pc to the other?
thx
Of course cx_Oracle can work with server working on other machine. But on client machines you will have to install Oracle client and configure it. I don't know if Oracle client installation can be added to installer of your application. Normally it is huge (600 MiB or so) so it is not a good idea. Then on all client machines you will have to configure Oracle client: set ORACLE_HOME, run Oracle tools to configure connection with database etc.
The only "light" solution I know is to use JDBC from Jython or Java. In this scenario you can use "thin" version of connect string that requires only some .jar libraries. Such connect string looks like:
db = DriverManager.getConnection('jdbc:oracle:thin:169.0.1.225:1521:test_db', 'user', 'passwd')
On client machines it needs ojdbc6.jar and orai18n.jar on CLASSPATH. No installation, no configuration, simple and easy.