Make pkg.install respect __env__

This fixes #5209.