0

I have a shell script like below

#!/bin/bash
export ORACLE_HOME=/opt/app/oracle/product/12.1.0.2/client_1
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=/opt/app/oracle/product/12.1.0.2/client_1/lib
export PATH=$PATH:$LD_LBRARY_PATH

python my_python.py

It throws below error when triggered.

import cx_Oracle
ImportError: No module named cx_Oracle

If I run the exports in the command line and run the python my_python.py in the command line it works.

What am I missing when I tried to put them in the script file?

1 Answer 1

0

The exports are not related to the error you are getting - you would get an error from cx_Oracle itself if they were the problem. Instead, Python can't even find cx_Oracle to load.

Make sure both environments are running the same Python binary. If you installed cx_Oracle with pip install cx_Oracle --user then also make sure you are running the script as the same user.

Unrelated to the problem: this line is wrong export PATH=$PATH:$LD_LBRARY_PATH. It is not needed.

1
  • Thanks for your response. Even when I ran as the same user ( I was in the same session when I tried command line vs scripts) script was throwing. I have changed to '/usr/bin/python3.8 my_python.py' in the script - which worked. So, when I ran as shell script, somehow, was referring to old version (which didn't have cx_Oracle). So, like you mentioned, it is not export issue, rather shell referring to wrong version of Python.
    – Kay Gee
    Aug 11, 2020 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.