0

I am attempting to connect to an external Oracle database using cx_Oracle on PythonAnywhere.com.

I have followed the instructions available on Oracle's website, GitHub, StackOverflow and the python anywhere forum but struggle to resolve the issue cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory".

The main instructions I followed were https://www.oracle.com/au/database/technologies/instant-client/linux-x86-64-downloads.html but it is unclear how I complete this task as a Python Anywhere user.

I have uploaded and unzipped the instant client files and tried every which way to get $LD_LIBRARY_PATH to do something but, to be honest, it isn't fully making sense.

Any help would be greatly appreciated.

Adam Williamson
  • 295
  • 4
  • 12
  • Are you trying to use the library from code that's running in a console or a scheduled/always-on task? Or from a website? If it's the latter, then I don't think it will work -- `LD_LIBRARY_PATH` is set before the website starts up, so it won't be possible to change it. If it's the former, could you give some more details about where you installed the client files in your PythonAnywhere account? – Giles Thomas Jan 21 '20 at 12:33
  • 1
    Hi Giles, good to hear from the man himself, big fan of Python Anywhere. This is for a flask web app, it is an API that needs to write some records to a remote Oracle DB when interacted with. – Adam Williamson Jan 22 '20 at 05:48
  • Always glad to help! Unfortunately I think it's bad news this time -- to pick up a library, it needs to be on the library path, which (as you know) can be extended using `LD_LIBRARY_PATH`. The problem is that that environment variable is read in by the runtime linker at the time a process starts up. And we don't currently have a way for you to set the environment variables at process startup; you can change them in the WSGI file, but that's run at a later point, so changes made to `LD_LIBRARY_PATH` won't have any effect if you do that. – Giles Thomas Jan 23 '20 at 13:08
  • You would be able to change it in a bash console, because there you could change the library path in one command, then run your script in the next -- the environment variable would be set at process startup for the script, so everything would work OK. I guess you could theoretically use the subprocess module to shell out from your website's code to run the Oracle stuff (setting the environment variable before) but that would be a pretty grim hack and I can't in good conscience recommend it :-( – Giles Thomas Jan 23 '20 at 13:10
  • Hey Giles, thanks for the follow-up, very much appreciated! Maybe I could pitch a feature for the backlog. Some sort of "commands to run before web service start" that execute prior to the web service. But then again, I might be a rare case wanting to do oracle stuff from Python Anywhere. – Adam Williamson Jan 24 '20 at 01:32
  • 1
    Yup, that's a great suggestion. TBH even something allowing you to tweak `LD_LIBRARY_PATH` would be a win. I'm surprised it wasn't already on our to-do list; I've added it, with an upvote on your behalf. – Giles Thomas Jan 25 '20 at 18:26
  • Another hack that might work depending on what you are doing / how your oracle library works: https://stackoverflow.com/a/21665823/2353123 – conrad Feb 05 '20 at 13:54

0 Answers0