Skip to content

Instantly share code, notes, and snippets.

@dtheodor
Last active August 29, 2015 14:23
Show Gist options
  • Save dtheodor/45c1d2615683b379131d to your computer and use it in GitHub Desktop.
Save dtheodor/45c1d2615683b379131d to your computer and use it in GitHub Desktop.
Oracle on ubuntu with python/sqlalchemy

Oracle with SQLAlchemy on Ubuntu

Installation

Download and install all instant client rpms from the Oracle website. For version 11.2.0.4.0 you probably need at least

oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm

Install them by using

sudo apt-get install alien dpkg-dev debhelper build-essential
sudo alien -k --scripts <the package>.rpm
sudo dpkg -i <the package>.deb

Follow every single instruction on https://help.ubuntu.com/community/Oracle%20Instant%20Client to set the environment and libraries up.

The sqlplus client should now work

sqlplus64 --help

Now you can install cx_Oracle

pip install cx_Oracle

Connect

With sqpplus

sqlplus64 'scott@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=ORCL)))'

With sqlalchemy

engine = create_engine("oracle+cx_oracle://scott:tiger@localhost:1521/ORCL")
engine.execute("SELECT username FROM all_users ORDER BY username").fetchall()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment