gpt4 book ai didi

找不到 Python 模块 "cx_Oracle"模块

转载 作者:太空狗 更新时间:2023-10-29 18:19:26 27 4
gpt4 key购买 nike

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

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

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

ImportError: DLL load failed: The specified module could not be found.

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

谁能帮帮我?提前致谢。

最佳答案

# - 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

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

  • python,只需在命令行上以交互模式运行 python。
  • cx_Oracle:查看下载文件的名称。
  • 甲骨文客户端:
    • 运行客户端包中的 sqlplus
    • 启动任务管理器并查看 sqlplus.exe 旁边是否有“*32”(=32 位)或没有(=64 位)
    • 如果您没有 sqlplus,请使用 dumpbin/headers oraocciXX.dll
  • 如果您使用的是 POSIX,您可能已经知道了。使用文件oraocciXX.so

最后,如果你还是不明白这里真的是傻瓜式的说明:

  • 确保您已安装 32 位版本的 python、cx_Oracle 和 Oracle Instant Client。这些也可以是 64 位的,但所有 3 个都必须相同。不能混合搭配。链接:
  • window :
    • 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: then oraocciXX is not found.正确设置环境变量。
    • ImportError:DLL 加载失败:%1 不是有效的 Win32 应用程序:您的 32/64 位不匹配。

关于找不到 Python 模块 "cx_Oracle"模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12538238/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com