简体   繁体   中英

Python cx_Oracle in Heroku

I'm struggling with this for one week. I'm trying to run a python flask app that connect with a remote Oracle Database using instant client version 11.2.0.3.0.

After a lot of problems, I ended using 3 buildpacks, two of them I need to customize and then I could install cx_Oracle in Heroku, but when I run the code I got the error:

import cx_Oracle
ImportError: libaio.so.1: cannot open shared object file: No such file or directory

Well, this error is very well documented, so I just needed to do:

$ apt-get install libaio1 libaio-dev

But the problem is how to run apt-get in a Heroku App? Using the third buildpack:

github.com/heroku/heroku-buildpack-apt

The other buildpacks:

github.com/Maethorin/oracle-heroku-buildpack
github.com/Maethorin/heroku-buildpack-python

After everything is configured, I runned a Heroku deploy and got the same error on execution. I could see in Heroku deploy log that heroku-buildpack-apt did its job but I got the same error in import cx_Oracle . Btw, just to be sure, I changed the forked python buildpack, that I'm using, to do pip uninstall cx_Oracle at each deploy so I can have a freshly compiled version of it.

At this point, the Great Internet was not able to help me anymore. Anywhere that I looked, I got the option to install libaio. I tried to search about using apt-get in Heroku App but everything points to heroku-buildpack-apt

I think the problem could be cx_Oracle cannot find the installed libaio and I setted a lot of Heroku App environment variables:

$ heroku config:set ORACLE_HOME=/app/vendor/oracle_instantclient/instantclient_11_2
$ heroku config:set LD_LIBRARY_PATH=/app/.apt/usr/lib/x86_64-linux-gnu:/app/vendor/oracle_instantclient/instantclient_11_2:/app/vendor/oracle_instantclient/instantclient_11_2/sdk:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib:/lib
$ heroku config:set LIBRARY_PATH=/app/.apt/usr/lib/x86_64-linux-gnu:/app/vendor/oracle_instantclient/instantclient_11_2:/app/vendor/oracle_instantclient/instantclient_11_2/sdk:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib:/lib
$ heroku config:set INCLUDE_PATH=/app/.apt/usr/include
$ heroku config:set PATH=/bin:/sbin:/usr/bin:/app/.apt/usr/bin
$ heroku config:set PKG_CONFIG_PATH=/app/.apt/usr/lib/x86_64-linux-gnu/pkgconfig
$ heroku config:set CPPPATH=/app/.apt/usr/include
$ heroku config:set CPATH=/app/.apt/usr/include

EDIT: I forgot to mention this:

When I run a heroku run ls -la /app/.apt/usr/lib/x86_64-linux-gnu where the libaio should be installed I got this:

drwx------ 3 u32473 dyno  4096 Dec 21  2013 .
drwx------ 3 u32473 dyno  4096 Dec 21  2013 ..
-rw------- 1 u32473 dyno 16160 May  9  2013 libaio.a
lrwxrwxrwx 1 u32473 dyno    37 May  9  2013 libaio.so -> /lib/x86_64-linux-gnu/libaio.so.1.0.1
drwx------ 2 u32473 dyno  4096 May 17 16:57 pkgconfig

But when I run heroku run ls -l /lib/x86_64-linux-gnu/libaio.so.1.0.1 there is no file there. So the real problem is where are libaio installed?

Anyone can help me make this work? Or there is another good substitution for cx_Oracle?

Thanks!

I solve this... the problem was really the location of the libaio.so .

I started to look for all possibles places where this lib could be installed. I found it in /app/.apt/lib/x86_64-linux-gnu and not in /app/.apt/usr/lib/x86_64-linux-gnu , where heroku-buildpack-apt think it was installed, nor in any of the system lib folders.

So I added this path in LD_LIBRARY_PATH and everything works fine!

Ty All!!!

I was also stuck with the same problems and fixed it after putting some efforts. I am sharing here the steps for hosting python flask app which connects external Oracle Database:

  • cd {ProjectDir}
  • pip install cx_Oracle
  • pip install gunicorn
  • Make file with name Procfile and put following in it: web: gunicorn yourapp:app --log-file=- //yourapp is your flask python file
  • pip freeze > requirements.txt
  • git init
  • create heroku
  • heroku buildpacks:add heroku/python
  • heroku buildpacks:add https://github.com/featurist/oracle-client-buildpack
  • heroku buildpacks:add https://github.com/heroku/heroku-buildpack-apt
  • heroku config:set BUILD_WITH_GEO_LIBRARIES=1 //This is for shapely python package (Optional)
  • create file with name Aptfile and put libaio1 in it
  • git push heroku master

设置DYLD_LIBRARY_PATH = $ ORACLE_HOME和LD_LIBRARY_PATH = $ ORACLE_HOME然后再试一次

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM