1

I'm trying to install cx_Oracle to use for a python script on a ubuntu vm. I first followed the first few steps listed on this site. I did originally get some overwrite errors which I got rid of by doing

sudo dpkg -i --force-overwrite (.deb file)

I had to overwrite twice, once when installing the cx_oracle .deb file and then the second time when installing the instantclient12.1-basic .deb file.

Then I tried to import cx_Oracle into python and got an ImportError. I then tried to install via pip and got the following error:

sudo -H pip install cx_oracle
Collecting cx_oracle
  Using cached cx_Oracle-5.2.1.tar.gz
Building wheels for collected packages: cx-oracle
  Running setup.py bdist_wheel for cx-oracle ... error
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-12y5OC/cx-oracle/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpgkWhJhpip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_ext
  building 'cx_Oracle' extension
  creating build
  creating build/temp.linux-x86_64-2.7-12c
  x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/oracle/12.1/client64 -I/usr/include/python2.7 -c cx_Oracle.c -o build/temp.linux-x86_64-2.7-12c/cx_Oracle.o -DBUILD_VERSION=5.2.1
  cx_Oracle.c:6:20: fatal error: Python.h: No such file or directory
   #include <Python.h>
                      ^
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Failed building wheel for cx-oracle Running setup.py clean for cx-oracle Failed to build cx-oracle Installing collected packages: cx-oracle Running setup.py install for cx-oracle ... error Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-12y5OC/cx-oracle/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-bPwpiX-record/install-record.txt --single-version-externally-managed --compile: running install running build running build_ext building 'cx_Oracle' extension creating build creating build/temp.linux-x86_64-2.7-12c x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/oracle/12.1/client64 -I/usr/include/python2.7 -c cx_Oracle.c -o build/temp.linux-x86_64-2.7-12c/cx_Oracle.o -DBUILD_VERSION=5.2.1 cx_Oracle.c:6:20: fatal error: Python.h: No such file or directory #include <Python.h> ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------

Command "/usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-12y5OC/cx-oracle/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-bPwpiX-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-12y5OC/cx-oracle/

I then looked into the error and found some askubuntu links such as this which recommended that I install python-dev

Here is the result of trying to install it:

sudo apt-get install python-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies: python-dev : Depends: libpython-dev (= 2.7.5-5ubuntu3) but it is not going to be installed Depends: python2.7-dev (>= 2.7.5-1~) but it is not going to be installed E: Unable to correct problems, you have held broken packages.

I tried to follow the steps in the general unmet dependencies post and still no luck. I also tried to install the two packages that it required and was only faced with even more dependencies.

sudo apt-get install libpython-dev python2.7-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies: libpython-dev : Depends: libpython2.7-dev (>= 2.7.5-1~) but it is not going to be installed python2.7-dev : Depends: libpython2.7-dev (= 2.7.6-8ubuntu0.3) but it is not going to be installed Depends: libexpat1-dev but it is not going to be installed E: Unable to correct problems, you have held broken packages.

Here is my sources list:

#This file is generated by Chef.  Do not edit!
deb  http://archive.ubuntu.com/ubuntu trusty main universe
deb  http://archive.ubuntu.com/ubuntu trusty-updates main universe
deb  http://archive.ubuntu.com/ubuntu trusty-security main universe

Am I missing any sources or is there something else that I should be doing in order to install cx_Oracle?

EDIT: I already have the oracle db client installed and so I had the following rpms installed already

oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm

oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm

oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm

I then installed:

cx_Oracle-5.2.1-11g-py27-1.x86_64.rpm

bbakp3
  • 11
  • 1
    Looks like I fixed my error. To anyone else in a similar situation. I used this instead of apt-get to install python-dev. After all the dependencies were installed I simply had to

    sudo -H pip install cx_Oracle

    – bbakp3 Feb 23 '17 at 19:17

1 Answers1

0

cx_Oracle comes with an extension .so file which doesn't seem to be compatible with the standard wheel bdist distribution. The bdist includes only standard python files so you have to include this explicitly as part of the data file in setup.py

ravi p
  • 1
  • 1
    Welcome to Ask Ubuntu! ;-) I recommend [edit]ing this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on Ask Ubuntu.) – Fabby May 28 '18 at 19:46