找不到Python模块"cx_Oracle"模块

Che*_*Xie 10 python oracle cx-oracle module

我最近在我的机器上安装了cx_Oracle模块,以便连接到远程Oracle数据库服务器.(我身边没有Oracle客户端).

  • Python:版本2.7 x86
  • Oracle:Verision 11.1.X x64
  • Cx_Oracle:优化版本 - 5.1.2-11g.win32-py2.7

然后每次我运行我的脚本时,它都会失败并打印以下消息:

ImportError:DLL加载失败:找不到指定的模块.

我在Here找到了一个相关的帖子,所以我想知道我是否必须在我这边调用python脚本的Oracle客户端.

谁能帮我吗?提前致谢.

Kas*_*yap 11

# - This import requires appropriate oraocciXX.dll to be available in PATH (on windows)
#   (Probably LD_LIBRARY_PATH or LD_LIBRARY_PATH64 on POSIX)
#     where XX is the oracle DB version, e.g. oraocci11.dll for Oracle 11g.
# - This dll is part of the Oracle Instant client pkg available here:
#     http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
# - Also ensure that python, cx_Oracle and Oracle Client are of same arch (32 or 64-bit)
#
import cx_Oracle
Run Code Online (Sandbox Code Playgroud)

你可以找到arch(32或64位):

  • 通过在命令行上以交互模式运行python来实现python.
  • cx_Oracle:查看下载文件的名称.
  • Oracle客户端:
    • 运行sqlplus,它是客户端软件包的一部分
    • 启动任务管理器,看看sqlplus.exe旁边是否有"*32"(= 32位)或不是(= 64位)
    • 如果你没有sqlplus,请使用 dumpbin /headers oraocciXX.dll
  • 如果你正在使用POSIX,你可能已经知道了.使用file oraocciXX.so

最后,如果你仍然不明白这里真的是假人的指示:

  • 确保已安装32位版本的python,cx_Oracle和Oracle Instant Client.这些也可以是64位,但对于所有3必须相同.不能混合和匹配.链接:
  • 视窗:
    • set PATH=%PATH%;C:\ProgFiles\OraClient\11_2
  • POSIX(Linux/Unix/Solaris ...)< - 未经测试..
    • export LD_LIBRARY_PATH=/path/to/your/32bit/oraocciXX.so
    • (64位) export LD_LIBRARY_PATH64=/path/to/your/64bit/oraocciXX.so
  • 运行path-to-python/python.exe -c "import cx_Oracle"以测试您的设置是否正常工作.
    • 如果它打印
    • 什么都没有:那就成功了.
    • ImportError: DLL load failed: The specified module could not be found:然后找不到oraocciXX.正确设置env vars.
    • ImportError: DLL load failed: %1 is not a valid Win32 application:您有32/64位不匹配.


bpg*_*rgo 8

是的,您必须安装Oracle客户端.

来自cx_ORacle自述文件

"请注意,为了使用cx_Oracle,需要安装Oracle客户端(或服务器).如果您不需要安装完整客户端的工具,建议安装更容易安装的Instant Client. "

编辑链接到Instant Client:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

  • 是的,oracle客户端和Python必须匹配才能使它们协同工作. (2认同)