Moving Python packages out of the Windows Roaming profile
On my work machine it has recently been taking quite a while to start-up when it is first turned on. This tends to mean there is too much data in the corporate roaming profile so I started to look into this. I recently installed ActivePython and added a few packages using the python package manager (pypm). This has dumped 150MB into my Roaming profile. This is the wrong place for this stuff on Windows 7. It should be in LOCALAPPDATA which would restrict it to just this machine (where I have Python installed) and not get copied around when logging in and out.
A search points up PEP 370 as being responsible for this design and this document suggests how to move the location. In the specific case of ActivePython the packages are stored in %APPDATA%\Python so we need to set the PYTHONUSERBASE environment variable to %LOCALAPPDATA%\Python. Editing the environment using the Windows environment dialog and using %LOCALAPPDATA% doesn't work correctly as the variable does not get expanded. However, we can set it to %USERPROFILE%\Local\Python which is expanded properly and produces right result.
Once the environment is setup we can move the package directory from %APPDATA%\Python to %LOCALAPPDATA%\Python and check everything is still available:
C:\Users\pat> pypm info PyPM 1.3.1 (ActivePython 184.108.40.206) Installation target: "~\AppData\Local\Python" (2.7) (type "pypm info --full" for detailed information) C:\Users\pat>pypm list numpy 1.6.0 NumPy: array processing for numbers, strings, records, a pil 1.1.7~2 Python Imaging Library xmpppy 0.5.0rc1 XMPP-IM-compliant library for jabber instant messaging.