cx_Oracle软件包在Crontab中不起作用 [英] cx_Oracle Package Not working inside Crontab

查看:391
本文介绍了cx_Oracle软件包在Crontab中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python脚本中使用cx_Oracle库.如果我直接从Linux终端通过python脚本执行代码,则我的代码运行良好,但是当我将其放入crontab时,出现以下错误.

I am using cx_Oracle library in my python script. My code works fine if I directly execute by python script from Linux terminal but when I put it in crontab I am getting following error.

!! DatabaseError:DPI-1047:无法加载Oracle客户端库:libclntsh.so:无法打开共享对象文件:没有此类文件或目录.参见 https://oracle.github.io/odpi/doc/installation.html寻求帮助

!!DatabaseError: DPI-1047: Oracle Client library cannot be loaded: libclntsh.so: cannot open shared object file: No such file or directory. See https://oracle.github.io/odpi/doc/installation.html for help

DPI-1005:无法获取Oracle环境句柄 !! Traceback(最近通话最近): 导入cx_Oracle !! DatabaseError:DPI-1005:无法获取Oracle环境句柄

DPI-1005: unable to acquire Oracle environment handle !!Traceback (most recent call last): import cx_Oracle !!DatabaseError: DPI-1005: unable to acquire Oracle environment handle

我用谷歌搜索了这个问题,当它使用crontab运行时似乎缺少一些环境变量. 我尝试在crontab中导出以下内容,但是它不起作用.

I googled this issue and It seems some environment variable missing when it ran using crontab. I try to export following in crontab but it does not work.

export LD_LIBRARY_PATH ='/usr/lib/oracle/11.2/client64/lib'

export LD_LIBRARY_PATH='/usr/lib/oracle/11.2/client64/lib'

如果我删除cx_Oracle软件包,则其他代码运行良好.我的机器上仅安装了一个版本的python.

If I remove cx_Oracle package other code runs fine. I have only one version of python installed on my machine.

您的Python版本是什么?是32位还是64位? Python 2.6. 64位

What is your version of Python? Is it 32-bit or 64-bit? Python 2.6 . 64 bit

您使用的cx_Oracle版本是什么? 版本6.0b1

What is your version of cx_Oracle? Version 6.0b1

您使用什么版本的Oracle客户端(例如Instant Client)?它怎么样 安装好了吗?它安装在哪里? oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

What is your version of the Oracle client (e.g. Instant Client)? How was it installed? Where is it installed? oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

您的操作系统和版本是什么? CentOS 6.7

What is your OS and version? CentOS 6.7

您设置了哪些环境变量?您如何设置它们? 导出LD_LIBRARY_PATH ='/usr/lib/oracle/11.2/client64/lib'

What environment variables did you set? How exactly did you set them? export LD_LIBRARY_PATH='/usr/lib/oracle/11.2/client64/lib'

推荐答案

由于它正在寻找oracle即时客户端路径,因此无法正常工作. 在shell脚本中,添加导出行并将其指向您的oracle客户端路径.接下来,继续编写您的Shell脚本.这将起作用!

It's not working since its looking for the oracle instant client path. In the shell script, add the export line and point it to your oracle client path. Next, keep writing your shell script. This will work!

#!/bin/sh
export LD_LIBRARY_PATH=/home/<user_name>/opt/oracle/instantclient_19_5:$LD_LIBRARY_PATH
/usr/anaconda3/bin/python /home/<user_name>/test/src/test.py

这篇关于cx_Oracle软件包在Crontab中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆