导入问题 cx_oracle

Problems importing cx_oracle

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

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 site and also 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

我在这里错过了什么?如果您需要更多信息,请告诉我,我会更新这个问题。

谢谢大家

如果您使用的是 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 客户端版本之间自动切换。