简体   繁体   中英

Environment variables in python

I want to set the environment variable for python. I had did all the stuff as to add in system variable under system path or even pythonpath. Even same under user variable but continuously getting error " PYTHONPATH ' is not recognized as an internal or external command, operable program or batch file."

By the type of error you are facing It's clear that you have problem installing python on windows . You did installed it, But it's env variables is not set and in your cmd you can not access it and gave you that error.

Follow this instruction Add Python to the PATH Environmental Variable

Also If you want to work with environment variables in python, you should use os module. like this:

to set value:

os.environ['myEnv'] = 'something'

to get value: os.environ.get('myEnv', 'defaultValue')

And remember if you set an environment variable, that variable is accessed only in context of your python code and will not be global for other applications.

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