How to change environment variables in python?

懵懂的女人 提交于 2019-12-22 08:13:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/14769326/how-to-change-environment-variables-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!