首页 > 解决方案 > cx_Oracle 在可执行文件中不起作用,但在 IDE 中起作用

问题描述

我正在使用 Python 3.8.5 (Anaconda) 并尝试使用 oracle 即时客户端库 19_9 连接到数据库并使用 cx_Oracle 8.1 此命令:

cx_Oracle.init_oracle_client(lib_dir=path )
con = cx_Oracle.connect(db_connection_string)

给出以下错误:

cx_Oracle.DatabaseError: DPI-1072 Oracle client library version is unsupported 

令人困惑的是,这根本不会发生在 IDE 中,而只会发生在可执行文件中。我正在使用 auto-py-to-exe 从 anaconda 提示符创建 exe。

谢谢您的帮助。

更新:

我得到:(其中 PATH 是我的客户端库路径)

load in dir PATH
load with name PATH\oci.dll
load by OS successful
validating loaded library
DPI-1072 Oracle client library version is unsupported

然后它再次尝试:

check module directory
module name is ...
load in dir PATH
load with name PATH\oci.dll
load by OS failure:The specified module could not be found
load with OS search heuristic
load with name oci.dll
load by OS failure: The specified module could not be found
Traceback ...

我使用的是 Windows 10 Pro,版本 20H2,OS build 19042.804(我不知道这是否有用)

标签: pythonoracleanacondaexecx-oracle

解决方案


将环境变量设置DPI_DEBUG_LEVEL为值 64 并查看 cx_Oracle 在这两种情况下尝试加载的内容。如果 Oracle 客户端库太旧(10g 或更早版本)或者该库可以加载但由于某种原因无法执行,则会发生该错误。例如,Windows 7 和 19c 客户端库会发生这种情况。


推荐阅读