与AWS Glue Python Shell的Oracle cx_Oracle问题连接 [英] Connection with Oracle cx_Oracle problem with AWS Glue Python Shell
问题描述
我正在研究AWS Glue Python Shell.我想将python shell与Oracle连接起来.我已经成功安装了psycopg2和mysql库,但是当我尝试使用cx_Oracle连接Oracle时,我已经成功安装了该库,但是遇到了错误
I am working on AWS Glue Python Shell. I want to connect python shell with 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
DatabaseError:DPI-1047:无法找到64位Oracle Client库: "libclntsh.so:无法打开共享对象文件:没有这样的文件或 目录"
DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory"
我已经尝试了以下事情
-
我已经从S3下载了
so
文件,并将其与代码文件并行放置在lib文件夹中
I have downloaded
so
files from S3 and placed it in lib folder in parallel to the code file
我已经使用os.environ设置了LD_LIBRARY_PATH,ORACLE_HOME
I have set the LD_LIBRARY_PATH, ORACLE_HOME using os.environ
我正在使用以下代码
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');
我应该能够在AWS胶水python shell上与oracle连接
I should be able to connect with oracle on aws glue python shell
推荐答案
已在响应中提及.需要在脚本启动之前设置LD_LIBRARY_PATH
.因此,一种避免使用LD_LIBRARY_PATH
的方法是在so
文件中设置rpath
.以下是所需的步骤.
As it has already been mentioned in the responses. LD_LIBRARY_PATH
needs to be set before the script starts. So, a way to avoid using LD_LIBRARY_PATH
is setting rpath
in the so
file. Below are the steps needed.
您将需要更新so
文件中的rpath
.可以使用patchelf
包来完成.
You will need to update rpath
in your so
file. This can be done using patchelf
package.
还请在运行sudo apt-get install libaio1
安装patchelf
Installing patchelf
sudo apt-get update
sudo apt-get install patchelf
sudo apt-get update
sudo apt-get install patchelf
要将rpath
更新到您的lib目录
To update rpath
to your lib directory
patchelf --set-rpath <absolute_path_to_library_dir> libclntsh.so
将具有更新的rpath
的so
文件上传到您的粘合环境lib目录.
Upload the so
files with updated rpath
to your glue env lib directory.
然后您可以在脚本中加载库.
In your script you can then load the library.
from ctypes import *
cdll.LoadLibrary('<absolute_path_to_library_dir>/libclntsh.so')
这篇关于与AWS Glue Python Shell的Oracle cx_Oracle问题连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!