【Python】cx_Oracleのインストール(準備編)

cx_Oracle

Oracle Linux 6.5にcx_Oracleをインストールし、Oracle Databaseに接続する。
今回はcx_Oracleをインストールする前に実施しておくべき設定を紹介する。

zlibのインストール

-zlibのパッケージを配置するディレクトリへ移動する。

# cd /usr/local/src

-wgetコマンドでパッケージをダウンロードする。

# wget http://zlib.net/zlib-1.2.11.tar.gz

~出力結果~
–2019-12-16 21:12:31– http://zlib.net/zlib-1.2.11.tar.gz
zlib.net をDNSに問いあわせています… IPv4アドレス
zlib.net|IPv4アドレス|:80 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています… 200 OK
長さ: 607698 (593K) [application/x-gzip]
`zlib-1.2.11.tar.gz’ に保存中

0% [ ] 0 –.-K/s 7% [=> ] 43,355 152K/s 37% [=============> ] 227,767 397K/s 100%[======================================>] 607,698 836K/s 時間 0.7s

2019-12-16 21:12:32 (836 KB/s) – `zlib-1.2.11.tar.gz’ へ保存完了 [607698/607698]

-/usr/local/src 直下にダウンロードしたzlib-1.2.11.tar.gzを解凍する。

# tar xvf zlib-1.2.11.tar.gz

-解凍したディレクトリにcdする。

# cd ./zlib-1.2.11

-makeの前準備をする。

# ./configure

~出力結果~
Building shared library libz.so.1.2.11 with gcc.
Checking for size_t… Yes.
Checking for off64_t… Yes.
Checking for fseeko… Yes.
Checking for strerror… Yes.
Checking for unistd.h… Yes.
Checking for stdarg.h… Yes.
Checking whether to use vs[n]printf() or s[n]printf()… using vs[n]printf().
Checking for vsnprintf() in stdio.h… Yes.
Checking for return value of vsnprintf()… Yes.
Checking for attribute(visibility) support… Yes.

-zlibをコンパイルする。

# make

makeをインストールしていない場合は以下でインストールしておく。
♯ yum install make

-makeがうまくいったかをチェックする。

# make check

~実行結果~
hello world
zlib version 1.2.11 = 0x12b0, compile flags = 0xa9
uncompress(): hello, hello!
gzread(): hello, hello!
gzgets() after gzseek: hello!
inflate(): hello, hello!
large_inflate(): OK
after inflateSync(): hello, hello!
inflate with dictionary: hello, hello!
*** zlib test OK ***

-zlibをインストールする。

♯ make install

~実行結果~
rm -f /usr/local/lib/libz.a
cp libz.a /usr/local/lib
chmod 644 /usr/local/lib/libz.a
cp libz.so.1.2.11 /usr/local/lib
chmod 755 /usr/local/lib/libz.so.1.2.11
rm -f /usr/local/share/man/man3/zlib.3
cp zlib.3 /usr/local/share/man/man3
chmod 644 /usr/local/share/man/man3/zlib.3
rm -f /usr/local/lib/pkgconfig/zlib.pc
cp zlib.pc /usr/local/lib/pkgconfig
chmod 644 /usr/local/lib/pkgconfig/zlib.pc
rm -f /usr/local/include/zlib.h /usr/local/include/zconf.h
cp zlib.h zconf.h /usr/local/include
chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h

Pythonのインストール

-Pythonのパッケージを配置するディレクトリへ移動する。

# cd /usr/local/src

-wgetコマンドでパッケージをダウンロードする。
インストールしたいバージョンが異なる場合はこちらを参考しURLを書き換える。

# wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz

~実行結果~
–2019-12-16 21:04:27– https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
www.python.org をDNSに問いあわせています… IPv4アドレス, IPv6アドレス
www.python.org|IPv4アドレス|:443 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています… 200 OK
長さ: 22673115 (22M) [application/octet-stream]
`Python-3.6.3.tgz’ に保存中

0% [ ] 0 –.-K/s 11% [===> ] 2,700,070 12.8M/s 31% [===========> ] 7,156,518 16.4M/s 58% [=====================> ] 13,366,054 20.6M/s 80% [==============================> ] 18,150,182 21.2M/s 89% [=================================> ] 20,181,798 15.2M/s 100%[======================================>] 22,673,115 16.9M/s 時間 1.3s

2019-12-16 21:04:29 (16.9 MB/s) – `Python-3.6.3.tgz’ へ保存完了 [22673115/22673115]

-/usr/local/src 直下にダウンロードした Python-3.6.3.tgzを解凍する。

# tar xvzf Python-3.6.3.tgz

-解凍したディレクトリにcdする。

♯ cd ./Python-3.6.3

-makeの前準備をする。
–prefixで指定したディレクトリにPythonをインストールする。

# ./configure –prefix=/usr/local/python

-Pythonのパッケージをコンパイルする。

# make

-Pythonをインストールする。

♯ make install

~zlibをインストールしていない場合、以下のエラーメッセージが出力される。~
zipimport.ZipImportError: can’t decompress data; zlib not available

Pythonのバージョン変更

-現行のPythonのバージョンはまだ変化がない。

# python –version

~実行結果~
Python 2.6.6

-Python3を使用するようにシンボリックリンクを作成する。

# ln -s /usr/local/python/bin/python3 /usr/local/bin/python
# ln -s /usr/local/python/bin/pip3.6 /usr/local/bin/pip

-環境変数を設定する。

# vi ~/.bash_profile

以下を追記し、上書き保存する。
export PATH=$PATH:/usr/local/python/bin

設定内容を反映させる。
# source ~/.bash_profile

本手順はPython3を使用するすべてのユーザーで実施する。

-Pythonのバージョンを確認する。

# python –version

~実行結果~
Python 3.6.3

-pipのバージョンを確認する。

♯ pip –version

~実行結果~
pip 9.0.1 from /usr/local/python/lib/python3.6/site-packages (python 3.6)

コメント

タイトルとURLをコピーしました