尝试安装 cx_oracle 时安装依赖项

尝试安装 cx_oracle 时安装依赖项

我正在尝试安装 cx_Oracle 以用于 ubuntu vm 上的 python 脚本。我首先按照列出的前几个步骤进行操作本网站。我最初确实遇到了一些覆盖错误,我通过以下方式摆脱了这些错误

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

我必须覆盖两次,一次是在安装时CX_Oracle.deb 文件,然后第二次安装时instantclient12.1-基本版.deb 文件。

然后我尝试将 cx_Oracle 导入 python,结果出现 ImportError。然后我尝试通过 pip 安装,结果出现以下错误:

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/

然后我查看了错误并找到了一些 askubuntu 链接,例如建议我安装 python-dev

这是尝试安装的结果:

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.

我尝试按照一般的步骤未满足的依赖关系发布,但仍然没有运气。我还尝试安装它所需的两个包,但只面临更多的依赖关系。

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.

以下是我的资料来源列表:

#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

我是否缺少任何来源或者我应该做其他什么才能安装 cx_Oracle?

编辑:我已经安装了 oracle db 客户端,因此我已经安装了以下 rpm

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

然后我安装了:

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

答案1

cx_Oracle 附带一个扩展 .so 文件,该文件似乎与标准 wheel bdist 发行版不兼容。bdist 仅包含标准 python 文件,因此您必须将其明确作为 setup.py 中数据文件的一部分包含

相关内容