1. ホーム
  2. パイソン

LinuxのPython 3.6.5でインストールされたcx_Oracleモジュール

2022-02-25 07:18:13
<パス

1. 環境を確認し、cx_Oracleパッケージをダウンロードする

[root@kkk ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.4 (Maipo)

[root@kkk ~]# python3 -V
Python 3.6.5

cx_Oracle source code package:
https://pypi.python.org/pypi/cx_Oracle/5.2.1#downloads


2. cx_Oracle パッケージを Linux にアップロードし、解凍する。

[root@kkk soft]# ls -l /soft/cx_Oracle-5.2.1.tar.gz 
-rw-r--r-- 1 root root 113416 Jan 27 20:40 /soft/cx_Oracle-5.2.1.tar.gz

tar -xzvf cx_Oracle-5.2.1.tar.gz

[root@kkk soft]# ls -ld cx_Oracle-5.2.1*
drwxrwxr-x 7 kkk kkk 4096 Jan 27 20:58 cx_Oracle-5.2.1
-rw-r--r-- 1 root root 113416 Jan 27 20:40 cx_Oracle-5.2.1.tar.gz


3. インストール前にrootユーザーに関連する環境変数を設定する

vi /etc/profile

export ORACLE_HOME=/u01/app/oracle/product/19.2.0.0.0/dbhome_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/bin:$PATH

source /etc/profile


4. インストールを開始する

cd /soft/cx_Oracle-5.2.1/

[root@kkk cx_Oracle-5.2.1]# python3 setup.py build
running build
running build_ext
building 'cx_Oracle' extension
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/u01/app/oracle/product/19.2.0.0.0/ dbhome_1/rdbms/public -I/u01/app/oracle/product/19.2.0.0.0/dbhome_1/sdk/include -I/usr/local/python3/include/python3.6m -c cx_Oracle.c -o build/temp.linux-x86_64-3.6-11g/cx_Oracle.o -DBUILD_VERSION=5.2.1
In file included from /u01/app/oracle/product/19.2.0.0.0/dbhome_1/rdbms/public/oci.h:3883:0,
                 from cx_Oracle.c:10:
/u01/app/oracle/product/19.2.0.0.0/dbhome_1/rdbms/public/ociap.h:11070:1: warning: function declaration isn? a prototype [-Wstrict-prototypes]
 void OCIThreadProcessInit();
 ^
/u01/app/oracle/product/19.2.0.0.0/dbhome_1/rdbms/public/ociap.h:11076:1: warning: function declaration isn? a prototype [-Wstrict-prototypes]
 boolean OCIThreadIsMulti();
 ^
In file included from /u01/app/oracle/product/19.2.0.0.0/dbhome_1/rdbms/public/oci.h:3886:0,
                 from cx_Oracle.c:10:
/u01/app/oracle/product/19.2.0.0.0/dbhome_1/rdbms/public/ocixmldb.h:216:1: warning: function declaration isn? a prototype [-Wstrict-prototypes]
 ub1 OCIXmlGetDiffBndVersion();
 ^
In file included from Variable.c:176:0,
                 from Cursor.c:246,
                 from Connection.c:761,
                 from SessionPool.c:138,
                 from cx_Oracle.c:203:
ObjectVar.c: In function ? .objectVar_Initialize?
ObjectVar.c:118:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < self->allocatedElements; i++) {
                   ^
ObjectVar.c: In function ? .objectVar_Finalize?
ObjectVar.c:135:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < self->allocatedElements; i++) {
                   ^
In file included from Cursor.c:246:0,
                 from Connection.c:761,
                 from SessionPool.c:138,
                 from cx_Oracle.c:203:
Variable.c: In function ? .ariable_NewByOutputTypeHandler?
Variable.c:926:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (var->allocatedElements < cursor->fetchArraySize) {
                                ^
In file included from Connection.c:761:0,
                 from SessionPool.c:138,
                 from cx_Oracle.c:203:
Cursor.c: In function ? .cursor_GetArrayDMLRowCounts?
Cursor.c:2440:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < rowCountArraySize; i++) {
                   ^
In file included from Connection.c:764:0,
                 from SessionPool.c:138,
                 from cx_Oracle.c:203:
Subscription.c: In function ? .iseTable_Initialize?
Subscription.c:451:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < numRows; i++) {
                   ^
Subscription.c: In function ? .iseQuery_Initialize?
Subscription.c:526:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < numTables; i++) {
                   ^
Subscription.c: In function ? .ise_Initialize?
Subscription.c:618:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < numTables; i++) {
                       ^
Subscription.c:660:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < numQueries; i++) {
                       ^
creating build/lib.linux-x86_64-3.6-11g
gcc -pthread -shared build/temp.linux-x86_64-3.6-11g/cx_Oracle.o -L/u01/app/oracle/product/19.2.0.0.0/dbhome_1/lib -lclntsh -o build/lib. linux-x86_64-3.6-11g/cx_Oracle.cpython-36m-x86_64-linux-gnu.so

[root@kkk cx_Oracle-5.2.1]# python3 setup.py install
running install
running bdist_egg
running egg_info
writing cx_Oracle.egg-info/PKG-INFO
writing dependency_links to cx_Oracle.egg-info/dependency_links.txt
writing top-level names to cx_Oracle.egg-info/top_level.txt
reading manifest file 'cx_Oracle.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'cx_Oracle.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-3.6-11g/cx_Oracle.cpython-36m-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/egg
creating stub loader for cx_Oracle.cpython-36m-x86_64-linux-gnu.so
byte-compiling build/bdist.linux-x86_64/egg/cx_Oracle.py to cx_Oracle.cpython-36.pyc
creating build/bdist.linux-x86_64/egg/EGG-IN

5. インストールが正常に行われたかどうかのテスト

Python側です。

[root@kkk soft]# python3
Python 3.6.5 (default, Jan 24 2020, 11:43:31) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> db1 = cx_Oracle.connect('scott/[email protected]:1521/pdb01')
>>> print(db1.version)
19.0.0.0.0


オラクル側

[oracle@kkk ~]$ sqlplus / as sysdba;

SQL*Plus: Release 19.0.0.0.0 - Production on Mon Jan 27 21:59:11 2020
Version 19.2.0.0.0

Copyright (c) 1982, 2018, Oracle.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.2.0.0.0


6. インストール時に発生したエラー

ImportError: libclntsh.so.19.1: cannot open shared object file: そのようなファイルやディレクトリはありません

When importing modules you will use $ORACLE_HOME/lib and add it to $LD_LIBRARY_PATH

Under /etc/profie add

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
source /etc/profile