Connect python to oracle

I installed the oracle client oracle client-dev and set the environment variable ORACLE_HOME. However, when I try to set tux_oracle (python setup.py build), I get the following: fatal error: oci.h: no such file or directory

+6
source share
3 answers

Well, the answer should set cx_Oracle, not tx_Oracle. A way to do this in Ubuntu:

  sudo apt-get -i alien 
  1. Convert RPM to deb:
  sudo alien -d oracle-instantclient11.2-sqlplus-11.2.0.2.0.i386.rpm 
  1. Install
      sudo dpkg -i oracle-instantclient11.2-basic_11.2.0.2.0-2_i386.deb 
  2. Set the ORACLE_HOME environment variable in the /etc/profile.d file by creating the oracle.sh file, which should contain:
  export ORACLE_HOME = / usr / lib / oracle / 11.2 / client
 source oracle.sh 
  1. Update LD_LIBRARY_PATH:
  sudo vi /etc/ld.so.conf.d/oracle.conf which must contain:  
 "$ ORACLE_HOME / lib"
 sudo ldconfig 
  1. Download and install cx_Oracle (depending on the version of the oracle and python you are using) from http://cx-oracle.sourceforge.net/ Convert rpm to deb again using a foreign one and install:
  sudo alien -d cx_Oracle-5.1-11g-py32-1.i386.rpm
 sudo dpkg -i cx-oracle_5.1-2_i386.deb 
  1. cx_Oracle is installed in / usr / lib / python 2.7 / dist-packages /. You have to do: sudo mv site-packages / cx_Oracle * dist-packages / sudo rmdir site-packages / sudo ln -s dist-packages site-packages

Now you should have no problems connecting to the oracle. From python type:

  import cx_Oracle 

To connect to the database, specify the connection string in tsnames.ora or directly:

  connection_string = 'username / password@ (DESCRIPTION = (ADDRESS = (PROTOCOL = tcp) (HOST = 127.0.0.1) (PORT = 1521)) (CONNECT_DATA = (SID = MY_SID)))' 
+6
source

I am using cx_oracle to connect to my Oracle database. Have you tried

+1
source

This header file can be found in the development package. For some reason, it is not included in the distribution by default. Take a look

http://my.opera.com/onyxluo/blog/cannot-find-oci-h-in-oracle9-2-client

Here is the contents of the page, for your convenience. I got it from the Google cache because the page was not available when I got there.

The reason for this problem is that the OCI (Oracle Call Interface) package is not installed in the Oracle9.2 client. By default, the path "oci.h" is $ ORACLE_HOME / rdbms / demo. This problem does not exist in Oracle Database 9.2.0.1. But for the Oracle 9.2.0.1 client, the OCI package is not part of the client, even if you choose the full client installation package.

Decision:

  • first install the Oracle 9.2.0.1 client.
  • In OUI (Oracle Universal Installer), use the same oracle with the Oracle 9.2.0.1 client, and then select Oracle Database install.
  • Select Customized in Database Setup
  • Uncheck Enterprise Manager and Oracle Database and others except OCI and OCCI.

After installing OCI, $ ORACLE_HOME / rdbms / demo will contain oci.h and other * .h files.

+1
source

Source: https://habr.com/ru/post/902368/


All Articles