导入cx_oracle时出现问题

时间:2017-04-27 11:09:59

标签: python gunicorn supervisord cx-oracle

我使用cx_Oracle(在virtualenv中)有一个Python项目(在Ubuntu 12.04上运行)。当我运行该项目时,我没有导入该模块的问题。现在我想使用主管来控制我的项目。当我从主管启动项目时,开始崩溃并引发异常:

File "/home/vagrant/scrapy/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
    worker.init_process()
  File "/home/vagrant/scrapy/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/home/vagrant/scrapy/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/home/vagrant/scrapy/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/vagrant/scrapy/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/vagrant/scrapy/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/vagrant/scrapy/local/lib/python2.7/site-packages/gunicorn/util.py", line 352, in import_app
    __import__(module)
  File "/vagrant/scrapy_server/flask_server/api.py", line 8, in <module>
    from resources.routes import routes
  File "/vagrant/scrapy_server/flask_server/resources/routes.py", line 1, in <module>
    from server.server import ServerStart, ServerStatus, ServerStop
  File "/vagrant/scrapy_server/flask_server/resources/server/server.py", line 8, in <module>
    from core.pool import ThreadPool
  File "/home/vagrant/scrapy/src/scrapy/scrapy_server/apps/core/pool.py", line 7, in <module>
    from resources.resources import Resources
  File "/vagrant/scrapy_server/flask_server/resources/resources.py", line 10, in <module>
    from repository.HotTypes import HotTypes
  File "/vagrant/scrapy_server/flask_server/resources/repository/HotTypes.py", line 1, in <module>
    from db_pg import DBPostgres
  File "/vagrant/scrapy_server/flask_server/resources/repository/db_pg.py", line 1, in <module>
    from resources.db_pg import DBPostgres as DBpostgresResources
  File "/vagrant/scrapy_server/flask_server/resources/db_pg.py", line 1, in <module>
    from core.dbcore import DBpostgresCore
  File "/home/vagrant/scrapy/src/scrapy/scrapy_server/apps/core/dbcore.py", line 3, in <module>
    import cx_Oracle
ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory

我按照this网站和this other网站的说明进行操作。但我无法解决这个问题。

主管conf文件是:

[program:api_server]
command = /home/vagrant/scrapy/bin/gunicorn api:app
directory = /home/vagrant/scrapy/src/scrapy/scrapy_server/flask_server/
environment = PATH="/home/vagrant/scrapy/bin/python", ORACLE_HOME="/usr/lib/oracle/12.1/client64", LD_LIBRARY_PATH="/usr/lib/oracle/12.1/client64/lib"
user = vagrant
autostart=true
autorestart=true
stderr_logfile=/var/log/api.err.log
stdout_logfile=/var/log/api.out.log
redirect_stderr = True

我在这里缺少什么?如果您需要更多信息,请告诉我,我会更新此问题。

谢谢大家

1 个答案:

答案 0 :(得分:2)

如果您使用的是Oracle Instant Client,请不要设置环境变量ORACLE_HOME。您需要设置的唯一内容是LD_LIBRARY_PATH以包含libclntsh.so的位置。

在您的环境变量中,您使用的是版本为12.1的Oracle Instant Client,但cx_Oracle本身似乎是使用11.2编译的。这需要纠正。您需要确保cx_Oracle是使用12.1编译的,或者您需要使用新的cx_Oracle 6.0b1,它会自动在不同的Oracle客户端版本之间自动切换。