【问题标题】:Django can't import cx_Oracle on OS X though python canDjango 不能在 OS X 上导入 cx_Oracle 虽然 python 可以
【发布时间】: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


【解决方案1】:

按照本页底部的说明安装 Oracle 即时客户端:

http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html

您可能还需要设置 DYLD_LIBRARY_PATH 或使用 otool -L 和 install_name_tool 进行调整。

【讨论】:

  • 我尝试了这些指令,除了关于 ~/lib.没有喜悦。我的问题中提到的 Ruby 脚本使用 otool -L 和 install_name_tool 进行调整。无论如何,谢谢。
  • 不客气。我不是 Mac 专家,但我确实可以使用 Mac,并且可以自己尝试这些步骤。我也熟悉 Django,所以如果我可以复制,我会告诉你。
猜你喜欢
  • 2016-05-09
  • 1970-01-01
  • 1970-01-01
  • 2011-06-15
  • 1970-01-01
  • 2011-08-08
  • 2018-05-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多