17

When installing a package via sudo pip-python (CentOS 6 package: python-pip-0.8-1.el6.noarch), I sometimes get permission issues with the installed packages being readable only by root.

Re-installing again one or two times usually fixes the problem. Has anyone experienced this? Or can anyone suggest any troubleshooting steps to nail down the cause?

Belmin Fernandez
  • 8,307
  • 9
  • 51
  • 75

2 Answers2

14

When you run a command using sudo, it will preserve the users umask. pip just installs files, it doesn't change access rights, so you'll end up with the files having the access rights set conforming to the current user's umask, which may be owner-readable only (0077) and therefore readable by root only.

That means you can set umask to something sensible like umask 0022 before running sudo pip install. Or use sudo su to open a root shell with default settings and then pip install.

mata
  • 67,110
  • 10
  • 163
  • 162
  • 1
    Initially, when one of our staff members reported this, I thought the same thing. However, it has now happened to me a couple of times where it sets restrictive permissions first but then, when I run it again without changing anything, it works fine. – Belmin Fernandez Jun 24 '12 at 21:04
  • Hm, that really seems strange, specially the 'without changin anything' part. I've only seen this problem when running pip through sudo, now I always run pip from the root shell with a proper umask, an it hasn't happened to me since. Don't know what's going on here... – mata Jun 25 '12 at 08:31
  • 1
    You can also run sudo bash, then umask 0022, then pip install – mabraham May 12 '16 at 14:23
  • Great tip, thanks. After installation I changed permissions: cd /usr/local/lib/python2.7/site-packages; chmod -R o+rw * and everything worked fine – artejera Jul 27 '18 at 15:54
  • 2
    @artejera that's a very bad idea as it opens a big security vulnerability. Now anybody can place or modify files there, and compromise any other use of these packages. Nothing below /usr should be world writeable! – mata Jul 27 '18 at 21:04
0

If executing pip with sudo, you may want sudo's -H flag

-H, --set-home set HOME variable to target user's home dir

e.g

sudo -H pip install virtualenv

Dr Manhattan
  • 13,537
  • 6
  • 45
  • 41