LoginSignup
2
2

More than 5 years have passed since last update.

macOS Sierraでのcx_Oracleのインストール方法

Last updated at Posted at 2017-02-19

概要

PythonからOracleに接続するためのライブラリであるcx_Oracleのインストール方法です。

環境

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.12.3
BuildVersion:   16D32
$ python --version
Python 3.5.2 :: Anaconda 4.2.0 (x86_64)
$ pip --version
pip 9.0.1 from /Users/nobukatsu/.pyenv/versions/anaconda3-4.2.0/lib/python3.5/site-packages (python 3.5)

手順

Instant Clientのダウンロードと配置

http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html

上記のページから

  • instantclient-basic-macos.x64-[バージョン番号].zip
  • instantclient-sdk-macos.x64-[バージョン番号].zip

の2つをダウンロードして解凍し、適当な場所に配置する。

例:

/Users/nobukatsu/devel/library/oracle/instantclient_12_1

シンボリックリンクを作成

$ pwd
/Users/nobukatsu/devel/library/oracle/instantclient_12_1
$ ln -s libclntsh.dylib.12.1 libclntsh.dylib
$ ln -s libocci.dylib.12.1 libocci.dylib

環境変数を設定する

.bash_profile等で環境変数を設定する。

export ORACLE_HOME=~/devel/library/oracle/instantclient_12_1
export PATH=$ORACLE_HOME:$PATH
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
export FORCE_RPATH=1

cx_Oracleのインストール

pip install --no-cache-dir cx_oracle

確認

以下を実行してエラーが出なければインストール成功。

python -c "import cx_Oracle"
2
2
1

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
2
2