Environment variables
Display Environment Variables
import os
print(os.environ) # print out all environment variables
print(os.environ("HOME")) # print out environment variable $HOME
			
env # in Linux and Mac system
printenv
			
Set Environment Variables
import os
os.environ["PROJECT_HOME"] = '/User/lchen'

del os.environ["PROJECT_HOME"] # remove an environment variable
			
export TEST='value' # define an environmental variable "TEST", or write it in .bashrc, .bash_profile, .profile
unset TEST # remove an environment variable
			
Python Environment Variables
  • PYTHONHOME, change the location of the standard Python libraries
  • PYTHONPATH, augment the default search path for module files
  • PYTHONSTARTUP, if this is the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive mode
  • PYTHONOPTIMIZE=4, equals to python -OOOO filename.py
  • PYTHONDEBUG, equals to python -d filename.py
  • PYTHONUSERBASE, define user base directory
  • Reference
  • Python Documentation