I remember when I first started using Python at work (for personal use tools, nothing I could share with anyone *cofcof*at least officially*cofcof*) I quickly found out that I needed to configure some environment variables for things to work smoothly. This felt, at a time, like a stylistic choice from the Python folks to get some configuration done in the simplest way possible while making it cross platform.

However, when I started using more and more tools that depended on environment variables, I realized that there’s a lot more than just %PATH% in life. By the time I moved my home computer to Linux I was already more than comfortable with the idea that something depended on an environment variable.

So if you are taking the journey to master Python, Emacs, Vim, etc. and live in a Windows environment, I strongly suggest you select one folder in your hard drive and set it to %HOME%. For Emacs for example, this determines where your config files will live. By default Emacs will do the right thing and put it in your %USERPROFILE% (C:\Users\<username>, but in older versions of Windows it was "Documents and Settings"). In my case I used "C:\HomeFolder\" which honeslty sounds quite dumb. But you know, cache invalidation and naming things, right? (that’s one quote worth keeping in mind when starting a new project. And naming folders). It’s pretty short, quite unique (usually "Ho" <TAB> is enough to get it autocompleted) and no spaces. All good attributes.

That’s where I keep the config for all my tools. Python packages 99% of the time will drop the "dot directories" in there, Emacs as mentioned does the same. The reason for this is that in Linux/Unix, each user in the computer gets their own directory in /home/username, where all the "stuff" (not only config but documents, etc.) will live. In a way, it’s a combination of (some) registry settings and %USERPROFILE%.

%HOME% is where the bin is

There’s one more thing I’ve added to my PATH that is semi-related to my home folder, which we usually don’t have in Windows but can come in quite handy, and that is a bin folder. Usually in Linux there’s a bin directory that contains the binaries (or, executables) for your tools. In Windows everything is spread out in the two Program Files folders, but if you start using more command line tools you’ll quickly realize it’s better to drop them all in one place.

So since these are things I call mostly from the command line I place my magic folder in C:\HomeFolder\cmdbin and for example that’s where I dropped the excellent GnuWin32/ezwinports utilities (Windows versions of grep, find, etc.). And then I added cmdbin to the PATH so from anywhere in the command line I can easily invoke the tools. By the way I also strongly advice against spaces in either of these directory names. It’s not that you can’t have spaces, but dealing with quoting paths all the time gets annoying fast.

Speaking of keeping things simple, the reason I didn’t just install Cygwin, is that I want to stay as much as possible in the "native" Windows world, so I can combine these tools with my older Win32 workflows more easily.

Dude, where’s my binaries folder?

One thing to notice, your user profile in many companies is setup in a way that you can login in different computers and have all your settings available. I’ve never quite liked this feature, honestly. It depends (as many things in Windows do) on the app developers playing nicely and doing things The Right Way (which we rarely do…​). So if you rely on the profile, you’ll be dissappointed sooner or later, and on top of that your first login on a different computer can take a while to sync all your files.

With the Home folder approach, it’s definitely up to you to every once in a while to sync your folder between different computers or keep a backup in case your hard drive dies. That’s the reason I put my bin inside the home folder. Every once in a while (usually when I configured something new and it took me a while to get it working) I zip the entire thing and keep that copy somewhere else. It happens rarely enough that it isn’t a huge pain, and at the same time if I have to move computers (which has already happened) getting my carefully created config up and running again it’s really straightforward.

There’s more

I also recommended looking around the interwebs for PYTHONPATH, PYTHON, HTTP_PROXY and HTTPS_PROXY. These are as well documented as %HOME%, but unlike the later they are much less opinionated. The first two obviously apply to Python, but the proxy ones affect so many tools that I wonder if they shouldn’t be set by default…​