Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change environment variables in python?

i have a simple python script ( test.py ):

import cx_Oracle
from cx_Oracle
tns = cx_Oracle.makedsn('10.10.1.3', 1521, 'etst')
db = cx_Oracle.connect('test', 'test', tns)

it is work if I run script with enviroument settings:

export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
./test.py

Can I set environment variables in python script ?

os.environ['LD_LIBRARY_PATH'] = "/usr/lib/oracle/11.2/client64/lib"
os.putenv('LD_LIBRARY_PATH', "/usr/lib/oracle/11.2/client64/lib/")

not work.

like image 814
Bdfy Avatar asked Jan 15 '23 06:01

Bdfy


1 Answers

You can set them that way, however $LD_LIBRARY_PATH is read by the loader which has already run before that therefore you must set that one externally beforehand.

like image 168
Ignacio Vazquez-Abrams Avatar answered Jan 22 '23 15:01

Ignacio Vazquez-Abrams