easy_install cx_Oracle (python package) on Windows

step 1 check python is 32 bit or 64

import platform
platform.architecture()[0]#'32bit'

or enter image description here step 2 install oracle client (32 bit or 64 bit depends on python version from step1)

  • download the oracle client from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-win32soft-098987.html(link for32 bit version) download and extract the zip files in one folder
  • the zip files are extracted to 'installation' in this case
  • the directory will appear like this enter image description here

    • click on install and set the path to 'base' and 'software' directories

      • software directory should be inside base directory(recommended)
      • in this case 'installed' directory is base and 'software' directory is for software path

      • set ORACLE_HOME path:

      • set the oracle home path to the 'software' directory as 'F:\softwares\oracle11g32\installed\software'

      • in cmd check 'echo %ORACLE_HOME%' to see if the path is set properly

step 3 install vcforpython27 or visual c++ 2008 express edition for python 2.7

  • download it from here https://www.microsoft.com/en-sa/download/details.aspx?id=44266 (used this in this case to avoid installation of whole visual c++ 2008 as mentioned in below)

  • it is a small package that contains c++ compilers for python 2.7

  • (Or)

  • visual c++ 2008 express edition ( https://www.microsoft.com/en-sa/download/details.aspx?id=5582 ) [it will around a 1 GB installation]

  • vcforpython27 will installed at 'C:\Users\Administrator\AppData\Local\Programs\Common\Microsoft'

  • enable show hidden folder in windows to this these directories enter image description here

  • set an environment variable with the name ' VS100COMNTOOLS' with value as 'C:\Users\Administrator\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0'
  • it should point to the point to the directory containing 'vcvarsall' batch fileenter image description here

  • echo %VS100COMNTOOL% to see if is pointing to the right directory in cmd

  • And do the steps below:(from:error: Unable to find vcvarsall.bat )

  • go to C:/Python27/lib/distutils the file msvc9compiler.py. Find in it the function find_vcvarsall and do following modification. Replace the line: productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC") with productdir = os.path.join(toolsdir) This is where vcvarsall.bat resides in this case (check, where vcvarsall.bat is in your installation).

install cx_Oracle

 the easy step: pip install cx_oracle

if all the above steps are followed properly, then it should work. It took lot of pain to figure this out. I hope it will be useful.

recommended to run:

 pip install --upgrade setuptools
 from : https://stackoverflow.com/questions/2667069/cannot-find-vcvarsall-bat-when-running-a-python-script

Honestly it is a hell of a lot easier to install cx_Oracle from one of the binary installers they have, than from source.

HOWTO for *nix:

  1. Browse to Instant Client for Linux x86 download page.

  2. Download the latest version of basic, sqlplus and sdk packages that fit your architecture (32 or 64bits):

    • oracle-instantclient<version>-basic-<version_full>.<arch>.rpm
    • oracle-instantclient<version>-sqlplus-<version_full>.<arch>.rpm
    • oracle-instantclient<version>-devel-<version_full>.<arch>.rpm.
  3. Install the RPMs using alien. For example, at the time of this writing:

    $ sudo alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
    
  4. Add necessary environment variables (I personally did put it in /etc/environment then logoff/back in to reload the env):

    ORACLE_HOME=/usr/lib/oracle/<version>/client64/lib/
    LD_LIBRARY_PATH=/usr/lib/oracle/<version>/client64/lib/
    
  5. Fix oracle's includes:

    $ sudo ln -s /usr/include/oracle/<version>/client $ORACLE_HOME/include  # for 32bits arch, OR
    $ sudo ln -s /usr/include/oracle/<version>/client64 $ORACLE_HOME/include  # for 64bits arch
    
  6. Create /etc/ld.so.conf.d/oracle-instantclient<version>-basic.conf and /etc/ld.so.conf.d/oracle.conf (for more recent versions, at least since 12.1) containing:

      /lib  
      /usr/lib/oracle/<version>/client/lib  ; for 32bits arch, OR
      /usr/lib/oracle/<version>/client64/lib  ; for 64bits arch
    
  7. Reload ldconfig cache (use -v flag if you want some verbose):

    $ sudo ldconfig
    

You might need to install libaio1.

HOWTO Install cx_Oracle

Assuming we have installed Oracle Instant Client 10, you have different alternatives to install cx_Oracle:

  1. Install with pip: $ pip install cx_oracle (linux only)
  2. Download the installer/.tar.gz file from the cx_oracle PyPI site

Older versions (version less than 5.1.2 are .msi and .rpm files) can be downloaded from here. Install the RPMs using alien. For example, at the time of this writing: $ sudo alien -i cx_Oracle-5.0-10g-py25-1.x86.rpm

To test, python -c 'import cx_Oracle; print cx_Oracle' should return the modules with its version.