Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top