Environment vars vs sys.path

I’ve read on here many times to use sys.path instead of environment variables, but after watching the presentation Jeremy did at GDC I thought it would be nice to have a thread that lists the pros and cons of the two.http://www.youtube.com/watch?v=64wpXowpvIU

Thoughts everyone? I’ve used both and thought sys.path was nice since env vars are not accessed the same on different platforms(at least the coding is not the same) at home I have a pc and work is a mac, so there is nothing to change in the code. But env vars can be used outside of maya and python for other tools as well.

I’m not sure what you mean? They both have uses- I use envvars when I am, say, setting up to launch another process (the python script we use to launch Maya). So I will set up the PYTHONPATH envvar because it will be inherited by the child process. Otherwise you should always use sys.path as the syntax is pythonic, how it is used internally is easier to understand, and it is hard to get things wrong.

a quick example, in the modular rigging dvd by 3D Buzz they show you how use os.environ to setup a path to your modules, but the same thing can be accomplished by appending the path with sys.path.append, so which would be better utilized, or what’s the big difference other than the env var can be used outside of python with other applications if needed?

I think you just described the key difference. Env vars are often useful for deployment tools, IT scripts and other things that run upstream of your Python tool.

well I feel sheepish :smiley: I guess that’s case closed.