For the following python script:
import os
os.system('PYTHONPATH=\user\...')
os.system('export PYTHONPATH')
....
Is there anyway we can “export” the PYTHONPATH variable to the shell after executing this script?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, this is not possible. When the Python process is launched, it gets its own copy of the environment, copied from the parent shell. The Python process can only modify the private copy, and changes are not propagated back to the parent process.
If you want to do something like this, the best you can get is to print the shell commands needed to do the desired environment variable changes, e.g.
and run the script using