Environment Variables

Since our development environment is controlled completely by passing environment variables from one process to its children, in general we allow all variables to flow freely. There are, however, a few circumstances in which we need to inhibit this flow.

Maya and Nuke, for example, add to the PYTHONHOME, and our launchers add to SITETOOLS_SITES (e.g., for the app’s special flavour of PyQt, etc.), and these changes must not propigate to child processes.

These tools allow us to manage those variables which should not propigate. In a “freeze”, the current state of given variables will be stored in the environment (for which you can provide part of the variable name). Then you can modify those variables for use, and launch the app. Upon Python startup, these tools will reset any variables which have been flagged with the default, unnamed, namespace.

Environ Variables


Where the default, unnamed, freeze is stored.


Do not use this directly, as the format is subject to change without notice. Instead, use sitecustomize.environ.freeze().

API Reference

sitetools.environ.freeze(environ, names, label=None)

Flag the given names to reset to their current value in the next Python.

  • environ (dict) – The environment that will be passed to the next Python.
  • names – A list of variable names that should be reset to their current value (as in environ) when the next sub-Python starts.
  • label (str) – A name for this environment freeze; the default of None will be unfrozen at startup.

This is useful to reset environment variables that are set by wrapper scripts that are nessesary to bootstrap the process, but we do not want to carry into any subprocess. E.g. LD_LIBRARY_PATH.

This may be called multiple times for the same label as it updates any existing freezes.


import os
from subprocess import call

from sitecustomize.environ import freeze

env = dict(os.environ)
env['DEMO'] = 'one'
freeze(env, ['DEMO'])
env['DEMO'] = 'two'

call(['python', '-c', 'import os; print os.environ["DEMO"]'], env=env)
# Prints: one
sitetools.environ.unfreeze(label, pop=False, environ=None)

Reset the environment to its state before it was frozen by freeze().

  • label (str) – The name for the frozen environment.
  • pop (bool) – Destroy the freeze after use; only allow unfreeze once.
  • environ (dict) – The environment to work on; defaults to os.environ.

A context manager to re-freeze the environment on exit.



# or

with unfreeze('maya'):
    # do something