0

This is solved, in as much as I can install, but I don't understand what is causing the issue

Whenever I install any package with PIP I get a Permission error as follows

sudo pip install <packagename>

Downloading/unpacking requests                                                                                                                                                      
Exception:                                                                                                                                                                          
Traceback (most recent call last):                                                                                                                                                  
  File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 104, in main                                                                                                     
    status = self.run(options, args)                                                                                                                                                
  File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 245, in run                                                                                                 
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)                                                                                      
  File "/usr/lib/python2.7/site-packages/pip/req.py", line 971, in prepare_files                                                                                                    
    location = req_to_install.build_location(self.build_dir, not self.is_download)                                                                                                  
  File "/usr/lib/python2.7/site-packages/pip/req.py", line 153, in build_location                                                                                                   
    _make_build_dir(build_dir)                                                                                                                                                      
  File "/usr/lib/python2.7/site-packages/pip/req.py", line 1225, in _make_build_dir                                                                                                 
    os.makedirs(build_dir)                                                                                                                                                          
  File "/usr/lib64/python2.7/os.py", line 157, in makedirs                                                                                                                          
    mkdir(name, mode)                                                                                                                                                               
OSError: [Errno 13] Permission denied: '/home/alex/build'    

I've taken to creating a tmp dir in my home directory, making it totally writable and then installing there as follows

mkdir temp
chmod 777 temp
cd temp/
sudo pip install packagename

Which then works. Any idea why I have to go through this?

Alex
  • 2,000
  • 4
  • 23
  • 41
  • 2
    There are at least 4 things that could cause this: `/home/alex/build` is not writable even for root (e.g., it's a link to a directory on a read-only filesystem); `/home/alex` is not traversable; `/home/alex/build` exists and is not a directory; `/etc/sudoers` specifies some special not-root-but-somewhat-super user for, e.g., wheel members sudoing pip. If you want to diagnose and debug the problem, we need more info (at least `ls -ld /home/alex /home/alex/build` and `cat /etc/sudoers`). If you just want to get past it, and you don't have anything you need in `build`, just blow it away. – abarnert Jun 21 '13 at 01:47
  • Oh, one more unlikely possibility: You could be using a `pip` that's configured specifically for non-sudo use, so it may have, e.g., immediately dropped root. People played with ideas like that in some of the predecessors to virtualenv, but in those cases the script ran out of the env's site-packages, not the system's; I've never heard of anything like this. I just wanted to mention it for completeness. – abarnert Jun 21 '13 at 01:50
  • @abarnert thanks for the response - I'm not sure why this confused me, and to be honest I feel a bit stupid - /home is an NFS mounted directory with no_sqsh_root not set, i.e. local root does not have write permission. I knew this already, and can't for the life of me figure out why this confused me... However, is it possible to specify where the temporary `build` folder gets placed - i.e. something like `sudo pip install --set-build /tmp/build `? – Alex Jun 25 '13 at 23:16
  • That said - put what you write as an answer (and add a bit about NSF, or I can edit it and add it) and then I'll accept - thanks. – Alex Jun 25 '13 at 23:18
  • Did `--build` work for you? If so, edit my answer or let me know so I can, because that will be helpful for future readers. – abarnert Jun 26 '13 at 18:04
  • @abarnert Yup, bang on the money. Thank you! – Alex Jun 27 '13 at 20:46

1 Answers1

1

There are only a few possible problems (listed in my comment to the question).

The first one is the one that turned out to be the actual problem here, and is probably also the most likely for future searchers/readers, so let's just focus on that.

If /home/alex/build is not writable even for root, you will get exactly this error from sudo pip. For example, if /home is mounted from a CD drive, not even root can write to a CD-ROM.

One common reason for people to have non-root-writable home directories is network shares. For example, if you mount an NFS share sqsh_root, your local root is not root to the share, so it can only write to world-writable directories. If you mount an SMB share to use domain permissions, the Windows-networking equivalent of the same will be true.

There are a number of parameters to pip that let you customize things. I think --build is the one you want, but try pip install --help to see all of them. (Also, make sure you're up to date. The pip devs have been adding and fixing convenience/customization features quite a bit while waiting on the near future of Python packaging to be decided.)

If worst comes to worst, you can do a --user installation without sudo, then use sudo to move the package and egg-info files from your user site-packages to the system.

abarnert
  • 354,177
  • 51
  • 601
  • 671