简体   繁体   English

使用 AWS Glue Python Shell 与 Oracle cx_Oracle 的连接问题

[英]Connection with Oracle cx_Oracle problem with AWS Glue Python Shell

I am working on AWS Glue Python Shell.我正在研究 AWS Glue Python Shell。 I want to connect python shell with Oracle.我想将 python shell 与 Oracle 连接。 I am successful installing psycopg2 and mysql libraries but when I tried to connect Oracle using cx_Oracle, I have successfully installed the library but I am facing the error我成功安装了 psycopg2 和 mysql 库,但是当我尝试使用 cx_Oracle 连接 Oracle 时,我已经成功安装了该库,但我遇到了错误

DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory"数据库错误:DPI-1047:找不到 64 位 Oracle 客户端库:“libclntsh.so:无法打开共享对象文件:没有这样的文件或目录”

I have tried following things我试过以下事情

  1. I have downloaded so files from S3 and placed it in lib folder in parallel to the code file我已经从 S3 下载了so文件并将其放置在与代码文件并行的 lib 文件夹中

  2. I have set the LD_LIBRARY_PATH, ORACLE_HOME using os.environ我已经使用 os.environ 设置了 LD_LIBRARY_PATH、ORACLE_HOME

I am using following code我正在使用以下代码

import boto3
import os
import sys
import site
from setuptools.command import easy_install

s3 = boto3.client('s3')
dir_path = os.path.dirname(os.path.realpath(__file__))
#os.path.dirname(sys.modules['__main__'].__file__)

install_path = os.environ['GLUE_INSTALLATION']
easy_install.main( ["--install-dir", install_path, "cx_Oracle"] )

importlib.reload(site)

import cx_Oracle

conn_str = u'{username}/{password}@{host}:{port}/{sid}'
conn = cx_Oracle.connect(conn_str)
c = conn.cursor()
c.execute(u'select * from hr.countries')
for row in c:
    print(row[0], "-", row[1])
conn.close()
print('hello I am here');

I should be able to connect with oracle on aws glue python shell我应该能够在 aws 胶水 python shell 上与 oracle 连接

As it has already been mentioned in the responses.正如在回复中已经提到的那样。 LD_LIBRARY_PATH needs to be set before the script starts. LD_LIBRARY_PATH需要在脚本启动之前设置。 So, a way to avoid using LD_LIBRARY_PATH is setting rpath in the so file.因此,避免使用LD_LIBRARY_PATH一种方法是在so文件中设置rpath Below are the steps needed.以下是所需的步骤。

You will need to update rpath in your so file.您将需要更新so文件中的rpath This can be done using patchelf package.这可以使用patchelf包来完成。

Please also include your libaio.so.1 in your so files which you might have generated by running sudo apt-get install libaio1还请附上您的libaio.so.1so的文件,你可能通过运行已生成sudo apt-get install libaio1

Installing patchelf安装patchelf

sudo apt-get update sudo apt-get install patchelf

To update rpath to your lib directoryrpath更新到您的 lib 目录

patchelf --set-rpath <absolute_path_to_library_dir> libclntsh.so

Upload the so files with updated rpath to your glue env lib directory.将带有更新的rpathso文件上传到您的胶水 env lib 目录。

In your script you can then load the library.在您的脚本中,您可以加载库。

from ctypes import *
cdll.LoadLibrary('<absolute_path_to_library_dir>/libclntsh.so')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM