Python 连接 Oracle 数据库时遇到的坑及解决办法

#编程技术 2019-10-29 16:45:30 | 全文 1069 字,阅读约需 3 分钟 | 加载中... 次浏览

👋 相关阅读


问题一:Python 连接 Oracle 数据库时报错 64-bit Oracle Client library cannot be loaded: “F:\app\Administrator\product\11.1.0\db_1\BIN\oci.dll

原因:Python3.5 版本 64 位 oracle11g 32位 sqlplus 32位,连接后,报错如上。需要一个64位的

  1. windows版 解决办法:

    1)下载 instantclient-basic 64位的 地址:https://www.oracle.com/technetwork/topics/winx64soft-089540.html

    2)下载后解压放到 python 安装目录下:E:\python\python\instantclient_11_2

    3)设置环境变量 path : E:\python\python\instantclient_11_2; 注意:后面必须添加 ; 隔开

    4)配置完环境变量后,重启 pycharm,run 项目,问题就解决了

  2. LINUX版解决办法:

    检查 linux 系统中 python2.7 版本和 python3.6 版本是 32 位还是 64 位的命令如下:

    import platform 
    platform.architecture()
    

    问题概况:centos 中自带64位的 python2.7.5 ,在 docker 中又安装了个 64 位的 python3.6,本地安装的是 3.5 版本的 python,将程序放到 docker 中运行,注意1:

    #!usr/bin/env python3
    

    (注意:我开始写的 python,后面没有改成 3,所以即使安装了 pandas-py3.6 ,运行依然提示: no module named ‘pandas’,紧急之下,我给系统的 python2.7 卸载了,大坑,导致 yum、gcc 都无法安装了,切记:直接在程序开头:将 python 改成 python3 就可以了,如果遇到其他情况,欢迎留言交流。 )

    注意2:python2.7、python3.6 都是64位,cx_Oracle 也是按照 python3.6 版本兼容下载的,为啥就是报错:DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded:

    解决办法如下:

    1)下载linux版64位的instanclient,我下载的是instanclient11-2:连接:

    https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

    2)在下载界面找到oracle对应的版本,复制连接

    3)在linux系统中新建文件夹,使用wget +连接,下载到当前新建的文件夹/home/instanclient中。

    4)将instanclient移动至python3.6安装目录下

    5)配置环境变量:

    6)在/etc/profile配置文件中配置:

    7)vi /etc/profile

    export

    LD_LIBRARY_PATH=/usr/local/lib/python3.6/instantclient_11_2:$LD_LIBRARY_PATH

    8)保存,退出

    9)source profile激活刚刚的配置文件

    10)再次运行时,即可成功。

以上 via:https://blog.csdn.net/weixin_39976528/article/details/83818542

问题二:ImportError :DLL load failed: 后面就是乱码

解决方法:import cx_Oracle 时,出现以上错误。将 oci.dll 文件复制一份放到 python 安装目录的 \Lib\site-packages 下面就可以了。

问题三:cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

解决方法:oraociei11.dll 复制到 python 安装目录的 \Lib\site-packages 下面

Edit | Last updated on 2024-04-21 11:10:27




×