如何在 Docker CI/CD 管道中的 Python 中找到 Oracle Instant Client
How to locate Oracle Instant Client in Python in Docker CI/CD pipeline
我正在尝试连接到 oracle DB 以执行一些 SQL 查询并通过 python 脚本获取数据。我已导入 cx_Oracle 并尝试 connecting.I 得到错误 - Exception - DPI-1047:找不到 64 位 Oracle 客户端库:“libclntsh.so:无法打开共享对象文件:没有这样的文件或目录”。请参阅 https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html 以获得帮助。
我下载了 instaclient 并在我的脚本中使用了它,它使用以下命令工作:
LOCATION = r"C:\instantclient_19_5"
os.environ["PATH"] = LOCATION + ";" + os.environ["PATH"]
但现在我需要在 CI CD 管道中使用它。我已经为 instaclient 创建了一个 docker 图像,并且 python 我正在尝试将其用于我的脚本。但我不确定如何在脚本中使用添加 instaclient 位置(如上面的代码片段)你能帮我解决这个问题吗?
如果您要部署到 Windows(或 macOS),您可以使用新的 cx_Oracle 8 init_oracle_client()
函数,它比摆弄 PATH 更受欢迎。
然而,您似乎正在部署到 Linux,这意味着系统库搜索路径需要包含所有库目录 在 进程启动之前。因此,您需要使用 ldconfig
或设置 LD_LIBRARY_PATH
,就像传统上在 Linux 上使用的那样。 cx_Oracle 文档 Installing cx_Oracle on Linux and Locating the Oracle Client Libraries 涵盖了这一点。
另请参阅 Linux developers and for basic Oracle Instant Client. If you are not on an RPM based system, check out the sample Docker files in Docker for Oracle Database Applications in Node.js and Python 的样本 docker 图片。
总而言之,从 here 下载 Oracle Instant Client Basic 或 Basic Light 软件包。如果您有 ZIP 文件,那么 运行 类似于:
RUN echo /opt/oracle/instantclient_19_8 > /etc/ld.so.conf.d/oic.conf && \
ldconfig
详细信息因您使用的 Docker 基础映像以及您是要从 ZIP 文件还是 RPM 安装 Instant Client 而异。
我正在尝试连接到 oracle DB 以执行一些 SQL 查询并通过 python 脚本获取数据。我已导入 cx_Oracle 并尝试 connecting.I 得到错误 - Exception - DPI-1047:找不到 64 位 Oracle 客户端库:“libclntsh.so:无法打开共享对象文件:没有这样的文件或目录”。请参阅 https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html 以获得帮助。
我下载了 instaclient 并在我的脚本中使用了它,它使用以下命令工作:
LOCATION = r"C:\instantclient_19_5"
os.environ["PATH"] = LOCATION + ";" + os.environ["PATH"]
但现在我需要在 CI CD 管道中使用它。我已经为 instaclient 创建了一个 docker 图像,并且 python 我正在尝试将其用于我的脚本。但我不确定如何在脚本中使用添加 instaclient 位置(如上面的代码片段)你能帮我解决这个问题吗?
如果您要部署到 Windows(或 macOS),您可以使用新的 cx_Oracle 8 init_oracle_client()
函数,它比摆弄 PATH 更受欢迎。
然而,您似乎正在部署到 Linux,这意味着系统库搜索路径需要包含所有库目录 在 进程启动之前。因此,您需要使用 ldconfig
或设置 LD_LIBRARY_PATH
,就像传统上在 Linux 上使用的那样。 cx_Oracle 文档 Installing cx_Oracle on Linux and Locating the Oracle Client Libraries 涵盖了这一点。
另请参阅 Linux developers and for basic Oracle Instant Client. If you are not on an RPM based system, check out the sample Docker files in Docker for Oracle Database Applications in Node.js and Python 的样本 docker 图片。
总而言之,从 here 下载 Oracle Instant Client Basic 或 Basic Light 软件包。如果您有 ZIP 文件,那么 运行 类似于:
RUN echo /opt/oracle/instantclient_19_8 > /etc/ld.so.conf.d/oic.conf && \
ldconfig
详细信息因您使用的 Docker 基础映像以及您是要从 ZIP 文件还是 RPM 安装 Instant Client 而异。