LoginSignup
8
8

More than 5 years have passed since last update.

Python から Oracle DB にアクセスする

Posted at

1.Instant Client Downloads for Linux x86-64をインストール

Instant Client Downloadsから、以下をダウンロード

  • oracle-instantclient-basic-10.2.0.5-1.x86_64.rpm
  • oracle-instantclient-devel-10.2.0.5-1.x86_64.rpm
  • oracle-instantclient-sqlplus-10.2.0.5-1.x86_64.rpm

ダウンロードしたら、rpmパッケージをインストールします。

$ sudo rpm -ivh oracle-instantclient-basic-10.2.0.5-1.x86_64.rpm 
$ sudo rpm -ivh oracle-instantclient-devel-10.2.0.5-1.x86_64.rpm
$ sudo rpm -ivh oracle-instantclient-sqlplus-10.2.0.5-1.x86_64.rpm

2.環境変数の設定

2-1.ORACLE_HOME の設定

export ORACLE_HOME=/usr/lib/oracle/10.2.0.5/client64

2-2.PATH の設定

export PATH=$PATH:$ORACLE_HOME/bin

2-3.include の設定

sudo ln -s /usr/include/oracle/10.2.0.5/client64 /usr/lib/oracle/10.2.0.5/client64/include

2-4.ld の設定

$ sudo vim /etc/ld.so.conf.d/oracle.conf

以下を書き込みます。

/usr/lib/oracle/10.2.0.5/client64/lib/

保存したら、次のコマンドを実行

$ sudo /sbin/ldconfig

3.cx_Oracle をインストール

$ /usr/local/python2.7/bin/python setup.py build
$ sudo cp build/lib.linux-x86_64-2.7-10g/cx_Oracle.so /usr/local/python2.7/lib/python2.7/site-packages/

4.接続の確認

$ /usr/local/python2.7/bin/python
>>>import cx_Oracle
>>>

参考

偏った言語信者の垂れ流し

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8