Sometimes a virtualenv isn’t what you want. I often want my account to have a particular python package (like bpython), but I also like to keep things clean and compartmentalized. One answer is installing the package to a standard place within your user account’s home folder. Python is already setup for this, as you can see if you run python -m site.

sys.path = [
    '/Users/someuser',
    '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
    '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
    '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
    '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
    '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
    '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
    '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
    '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
    '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
    '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
    '/Library/Python/2.7/site-packages',
]
USER_BASE: '/Users/someuser/Library/Python/2.7' (doesn't exist)
USER_SITE: '/Users/someuser/Library/Python/2.7/lib/python/site-packages' (doesn't exist)
ENABLE_USER_SITE: True

You’ll see that python is looking for USER_BASE and USER_SITE directories in particular locations. Let’s create them:

mkdir -p ~/Library/Python/2.7/lib/python/site-packages

I also like to make this symlink so that your site-packages appears in a more standard place:

ln -s lib/python/site-packages ~/Library/Python/2.7/site-packages

Now tell distutils that the packages should be installed here:

cat <<'EOM' >~/.pydistutils.cfg
[install]
install-base=$HOME/Library/Python/$py_version_short
install-purelib=$base/site-packages
install-platlib=$base/site-packages
install-scripts=$base/bin
install-headers=$base/include
install-data=$base/data
EOM

The big problem here is that this setup can interfere with virtualenv or at times when you want to install a package globally. So I use these aliases to enable disable this file. Normally I leave it disabled, and when I want to install some packages to my user account instead of a virtualenv, I enable the file

alias pydistutilson='mv -i ~/.pydistutils.cfg.off ~/.pydistutils.cfg'
alias pydistutilsoff='mv -i ~/.pydistutils.cfg ~/.pydistutils.cfg.off'