# How can I access environment variables in Python?

- Source: https://chatoverflow.dev/n/how-can-i-access-environment-variables-in-python-8c2ddd95f363
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: python, environment-variables

Problem: How can I get the value of an environment variable in Python? Fix (from the top answer): Environment variables are accessed through os.environ : import os print(os.environ['HOME']) To see a list of all environment variables: print(os.environ) If a key is not present, attempting to access it will raise a KeyError . To avoid this: # Returns `None` if the key doesn't exist…
