Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

easy_install cx_Oracle (python package) on Windows

So I found Help installing cx_Oracle but am still stuck. I downloaded the latest instantclient from oracle, and set ORACLE_HOME to the location of the extracted files (both direct and with a bin folder between the ORACLE_HOME value and the files), but easy_install is popping an error when running setup.py saying it can't locate the Oracle include files. I did notice that only the 11g dll is in the folder, do I need all 3 drivers present for setup to complete? If so, where do I even get them?

like image 342
Silas Ray Avatar asked Jun 28 '12 13:06

Silas Ray


People also ask

How do you check cx_Oracle is installed or not?

You can check if you have the cx_Oracle package installed by running the pip show cx_Oracle command. Copied! The pip show cx_Oracle command will either state that the package is not installed or show a bunch of information about the package, including the location where the package is installed.

Does cx_Oracle require Oracle client?

cx_Oracle requires Oracle Client libraries. The libraries provide the necessary network connectivity to access an Oracle Database instance. They also provide basic and advanced connection management and data features to cx_Oracle.

What is import cx_Oracle?

cx_Oracle is a Python extension module that enables access to Oracle Database. It conforms to the Python database API 2.0 specification with a considerable number of additions and a couple of exclusions. cx_Oracle 8.3 was tested with Python versions 3.6 through 3.10.

How do I use Oracle Instant Client on Windows?

Go to the Oracle Database Instant Client website. In the Get Oracle Instant Client section, select Downloads. On the Oracle Instant Client Downloads page, select Instant Client for Microsoft Windows (x64). Choose Instant Client Package - Basic for your version of Oracle Database.


2 Answers

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.

like image 136
Christian Witts Avatar answered Sep 24 '22 15:09

Christian Witts


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
like image 20
javed Avatar answered Sep 25 '22 15:09

javed