The blog for the bleeding-edge news in the server of Research and Development.

Isolated User Installs in Python

← Blog

I don't really like virtualenv. In theory it's a great tool to isolate Python environments, but in practice I've never used it because of the context switching involved. Keeping track and activating and deactivating environments takes effort, and I'm extremely lazy.

direnv is a useful shell utility that automatically swaps out environment variables based on the current directory. Combined with an .envrc file, I've just set up a "lazy man's limited virtualenv" for standalone projects.

# .envrc

# force user installs into the isolated user environment
export PIP_USER=1

# add project bin/ to shell
PATH_add "$PWD/bin"

This doesn't copy the interpreter or do any fancy things that might be nice or sane for most people, but it overrides pip's installation process (setting it to user install mode and use the new user directory), makes Python load libraries from the same directory, and updates the $PATH.

Which is all I need, really.

(Up you go!)