Reboot to Refresh Environment Variables

date:2010-04-06 10:00
category:python, web development
tags:environment variables, idle, iis, python

I wasn’t aware that if you change Windows environment variables that are used by IIS then you need to reboot the machine for the changes to take effect. As described by David Wong

This is because NT services like IIS inherit their environment from services.exe, which does not get updated when you change system environment until you reboot.

This knowledge may save a couple of hours of frustration if you are running Python scripts on IIS through PyISAPIe.


If you add paths to your PYTHONPATH or PATH system variables to use a Python package (such as MapScript or GDAL), then the same script may run without problems in IDLE, but continue to produce errors when run through the web server.

If you are running a script in IDLE then you need to restart IDLE itself to refresh the environment variables.

Other Options

I’ve not tried this method myself but R. Teachout suggests a registry hack that allows you to override the Windows environment variables in IIS 6.

You can also override the environment variables in the Python scripts themselves. For example to change the GDAL_DRIVER_PATH variable use:

os.environ[“GDAL_DRIVER_PATH”] = “C:\ms4w\gdalplugins”

To print out current environment variables (assuming you are testing in IDLE):

print os.getenv(“GDAL_DRIVER_PATH”)


1. Thomas Wood **

The royal mail have not relaxed their copyright over the PAF, it was the Ordnance Survey that released their copy of the postcode centroids as part of their Opendata scheme.


2. geographika **

Thanks for the clarification - I’ve updated the post with an

additional link.

Add Comment