Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changes in environment variables are not reflected in python

trying to install spark, I've some problems when I try to set the system enviroment variables. I modify the PATH using:

“Advanced system settings” → “Environment Variables”

but when I call these variables from python, using the code:

import os
path = os.environ.get('PATH', None)
print(path)

The path that shows python don't have the modifications that I put. Thanks

like image 954
JAlex Avatar asked Apr 10 '26 00:04

JAlex


1 Answers

Any program invoked from the command prompt will be given the environment variables that was at the time the command prompt was invoked.

Therefore, when you modify or add an environment variable you should restart the command prompt (cmd.exe) and then invoke python to see the changes.

like image 191
napuzba Avatar answered Apr 11 '26 12:04

napuzba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!