简体   繁体   中英

execute export command to current terminal using python

I want to set environment in current terminal using python. I have tried below method but they all are executing in subterminal.

Ex 1 - export OpenCV_DIR=/home/root/cv_install/share/OpenCV/

I tried::
a) os.environ['OpenCV_DIR'] = "/home/root/cv_install/share/OpenCV/"
b) subprocess.run("export OpenCV_DIR=/home/root/cv_install/share/OpenCV/", shell=True)
c) os.system("export OpenCV_DIR=/home/root/cv_install/share/OpenCV/", shell=True)

None of the above listed method worked for me. Can anyone help me out.

have u tried

shell=True 

it will help you it will enable command to be enabled in shell

subprocess.run("export OpenCV_DIR=/home/root/cv_install/share/OpenCV/", shell=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM