【发布时间】:2016-09-04 14:33:23
【问题描述】:
我遇到了一个非常奇怪的问题,我无法完全弄清楚,希望大家都能解决。按照this link 的步骤,我已经安装了Oracle 即时客户端和cx_Oracle,我可以在Python 中导入cx_Oracle 没问题。我在 virtualenv 中完成了所有这些工作。
问题是当我尝试时
./manage.py runserver
我明白了
raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading cx_Oracle module:
dlopen(/Users/shawn/Virtual/Django18/lib/python2.7/site-packages/cx_Oracle.so,
2): Library not loaded: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
Referenced from: /Users/shawn/Virtual/Django18/lib/python2.7/site-packages/cx_Oracle.so
Reason: image not found
当然,这正是 cx_Oracle.so 文件所在的位置。
所以我搜索并找到了this SO question,但运行 Ruby 脚本实际上会破坏我在 python 中的 cx_Oracle 导入,并且不能解决 django 问题。相反,它给出了下面的错误,无论是直接在 Python 中还是在 django 环境中。我该如何解决?我需要能够在 django 中导入 cx_Oracle!谢谢!
ImportError: dlopen(/Users/shawn/Virtual/Django18/lib/python2.7/site-packages/cx_Oracle.so,
2): Library not loaded: /Users/Shawn/Oracle/instantclient_11_2/
Referenced from: /Users/shawn/Virtual/Django18/lib/python2.7/site-packages/cx_Oracle.so
Reason: no suitable image found. Did find:
/Users/Shawn/Oracle/instantclient_11_2/: not a file
/Users/Shawn/Oracle/instantclient_11_2/: not a file
/usr/local/lib/: not a file
/usr/lib/: not a file
编辑: 我擦除并重新创建了我的 virtualenv。在我意识到我没有在与即时客户端可执行文件相同的目录中运行它之后,我重试了 Ruby 脚本。它从
运行和更新@executable_path/...
to
/Users/shawn/Oracle/...
我尝试在我的 virtualenv python 中导入 cx_Oracle,这次它成功了,而不是抛出错误。不幸的是,尝试运行我的 django 服务器仍然会说
Raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading cx_Oracle module: dlopen(/Users/shawn/Virtual/Django18/lib/python2.7/site-packages/cx_Oracle.so, 2): Library not loaded: libclntsh.dylib.11.1
Referenced from: /Users/shawn/Virtual/Django18/lib/python2.7/site-packages/cx_Oracle.so
Reason: image not found
我不明白为什么python可以导入它而django却不能。
【问题讨论】:
-
您是否从安装了 cx_Oracle 的虚拟环境运行 python?
-
是的。它很好地导入了 cx_Oracle
标签: python django oracle cx-oracle