Reboot to Refresh Environment Variables

date

2010-04-06 10:00

author

admin

category

python, web development

tags

environment variables, idle, iis, python

slug

reboot-to-refresh-environment-variables

status

published

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.

image

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”)
orphan


Comments

http://www.gravatar.com/avatar/feedaefbf39e7c87892041e50db4afa9?s=55&d=identicon&r=g

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.

Reply
http://www.gravatar.com/avatar/ec399a4765f732e1a2acd5ca7edd0fd5?s=55&d=identicon&r=g

2. geographika **

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

additional link.

Reply
Add Comment