After trying to install virtualenv with pip
$ pip install virtualenv
I got a permission denied error
IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/virtualenv.py'
So I used sudo to install virtualenv
$ sudo pip install virtualenv
But then a warning showed up:
The directory '/Users/petertao/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/petertao/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
What does sudo's -H flag do?
sudoand see that sudo manual page with-Hstating "set the HOME environment variable to the home directory specified by the target user's password database entry." - metatoasterpipcomplain about non-superuser permissions and ownership when running as the superuser?" is non-trivially interesting. As user3141593's well-authored answer explains,pipcomplains because creating superuser-owned subdirectories in non-superuser home directories is a bad idea. Fortunately, this question remained open long enough to receive a useful response. - Cecil Curry