Forums

pip permissions with Fabric

I'm trying to use Fabric via SSH to run pip install, but get the following traceback:

Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 742, in install
    **kwargs
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 1032, in move_wheel_files
    isolated=self.isolated,
  File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 346, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 317, in clobber
    ensure_dir(destdir)
  File "/usr/local/lib/python2.7/dist-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/defusedxml-0.4.1.dist-info'

I don't get this error when manually ssh-ing into PA and running the command. I'm not that familiar with how user permissions factor into this - what should I do?

Ok, found that I had to use the pip from the virtualenv, not sure why though?

Do you need to workon myenv before trying to do things in your virtualenv?

Hmm I had this previously:

run('workon {virtualenv}'.format(...))
run('pip install -r {site_folder}/requirements.txt'.format(...))

Do I need to run them together with &&?

Yes, the two "run" commands won't share state between each other. Using the path to the virtualenv pip may be neater...

Thanks Harry - how would I get the environment variables from my postactivate file?

I'm using virtualenvwrapper, not sure if that's contributing to the problems.

I had asked something similar where I needed to add source virtualenvwrapper.sh, but it seems like it doesn't help.

source virtualenvwrapper.sh && workon thing && pip install stuff should work... what's going wrong?

Found the reason - my stupidity. I forgot --settings with manage.py.

Thanks Harry!