Forums

Connecting to an Oracle Database

Is it possible to connect my PythonAnywhere with an external Oracle database?

The two ways I've done so in the past are with SQL*Plus and JayDeBeApi, but I haven't been able to get either of those to work here. Are either of those possible or are there other methods?

That should work from a paid account. What errors are you getting?

I'm new to PythonAnywhere and I think I'm just confused about how to install SQL*Plus. Could you walk me through that?

Ah, I'm sorry, I missed something when I did my original post -- it looks like we'd need to install some extra stuff to get Oracle to work. Unlike PHP, there's no pure-Python client for Oracle.

It does sound like there's a slightly messy workaround, though -- do you have a Linux machine available from which you could copy some Oracle client files?

I do

OK, so you need to get hold of the Oracle client libraries (the .so and .ora files) and then put them somewhere in your file space. Then (as per this Stack Overflow post) set ORACLE_HOME and TNS_ADMIN to the places where you've installed them. Then you should be able to install the Python Oracle client, cx_oracle, using this command:

pip install --user cx_oracle

Caveat -- I don't have access to the Oracle client libraries, so I've not tried this myself. So, no guarantees. But from the SO post it sounds like it should work here.

Ok, I'm closer. I was able to install cx_Oracle, but whenever I import it I get the following error.

Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: libaio.so.1: cannot open shared object file: No such file or directory

I have the libaio.so.1 file that I need, but I'm not sure how to configure it. Any ideas?

Thanks for your help!

I'm guessing here (because Oracle might do things differently) but I suspect that if you add the directory containing that file to your LD_LIBRARY_PATH before starting the Python process then it will be able to pick it up. eg., in bash

export LD_LIBRARY_PATH=/path/to/folder/containing/lib/file:$LD_LIBRARY_PATH
python yourscript.py

That did it. Thanks!

Awesome, thanks for confirming!

-