'Permission denied' error when using pip install in virtualenv
Asked Answered
U

2

15

Edit: FIXED!

Just had to chown the .cache directory

I've tried the virtualenvwrapper docs instructions, I've tried this guy's instructions as well as these...I've tried sudo pip uninstall virtualenv , sudo pip uninstall virtualenvwrapper, sudo pip3 uninstall virtualenv, sudo pip3 uninstall virtualenvwrapper before attempting each set of instructions. I've looked at other SO posts like this one, but the sudo issue isn't the same as my own. By this, I mean that I don't use sudo when making the virtualenv, and if I try to use sudo to pip install a package, it'll just say that I've already installed the package (outside of the virtualenv).

I've also tried doing pip install --user virtualenv(wrapper)

Here's what I did:

~ $ sudo pip3 install virtualenv
Downloading/unpacking virtualenv
  Downloading virtualenv-13.0.3-py2.py3-none-any.whl (1.7MB): 1.7MB downloaded
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...
~ $ mkdir ~/.virtualenvs
~ $ sudo pip3 install virtualenvwrapper
Downloading/unpacking virtualenvwrapper
  Downloading virtualenvwrapper-4.5.1-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): virtualenv-clone in /usr/local/lib/python3.4/dist-packages (from virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): stevedore in /usr/local/lib/python3.4/dist-packages (from virtualenvwrapper)
Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python3.4/dist-packages (from virtualenvwrapper)
Installing collected packages: virtualenvwrapper
Successfully installed virtualenvwrapper
Cleaning up...
~ $ export WORKON_HOME=~/.virtualenvs/

Then I added these two lines to my .bashrc: (I also tried setting VIRTUALENVWRAPPER_PYTHON to /usr/bin/python)

source /usr/local/bin/virtualenvwrapper.sh
VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3'

Next I tried this:

~ $ mkvirtualenv test
New python executable in test/bin/python
Installing setuptools, pip, wheel...done.
(test)~ $ pip install numpy
Collecting numpy
  Using cached numpy-1.9.2.tar.gz
Building wheels for collected packages: numpy
Exception:
Traceback (most recent call last):
  File "/home/aweeeezy/.virtualenvs/test/local/lib/python2.7/site-packages/pip/basecommand.py", line 223, in main
    status = self.run(options, args)
  File "/home/aweeeezy/.virtualenvs/test/local/lib/python2.7/site-packages/pip/commands/install.py", line 291, in run
    wb.build(autobuilding=True)
  File "/home/aweeeezy/.virtualenvs/test/local/lib/python2.7/site-packages/pip/wheel.py", line 754, in build
    ensure_dir(output_dir)
  File "/home/aweeeezy/.virtualenvs/test/local/lib/python2.7/site-packages/pip/utils/__init__.py", line 70, in ensure_dir
    os.makedirs(path)
  File "/home/aweeeezy/.virtualenvs/test/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/home/aweeeezy/.virtualenvs/test/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/home/aweeeezy/.virtualenvs/test/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/home/aweeeezy/.virtualenvs/test/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/home/aweeeezy/.cache/pip/wheels/4b'

Why can't virtualenv just work?

Unfaithful answered 4/6, 2015 at 23:44 Comment(7)
Looks like one of the directories is funky. Won't let you in...Delorasdelorenzo
Make sure to source the venv before, so you don't have any dependencies to your original environment.Kinesthesia
@JosephSeungJaeDollar, like source ~/.virtualenvs/test? This won't work because the venv is a directory. edit: you mean, source ~/virtualenvs/test/bin/activate, right? Thpat still doesn't help.Unfaithful
In what way did you chown the .cache directory? who did you set the new owner to? Did you change the permissions?Capreolate
This was fixed in pip version 7.1.1 (2015-08-20) pip.readthedocs.org/en/stable/newsNotogaea
add Edit: at the end of the question. Answers were useful at the time of the question.Elviraelvis
@Unfaithful add your EDIT as an answer, so people will see itMinneapolis
C
16

I think that if you do that pip install numpy --no-cache-dir it will work.

If you run pip --help you will find:

--no-cache-dir Disable the cache.

Hope that it can help to someone in the future.

Canyon answered 22/6, 2016 at 23:14 Comment(2)
This 100% helped me today in case someone comes across the same issue. One other thing though is I removed the virtual environment completely and started over using this command in addition to --user. Thanks, Vladir!Urethrectomy
Good that it helped @TravisVOX.Canyon
S
8

you need to change the owner of directory of pip.

run chown -R <user>:<group> /home/aweeeezy/.cache/pip.

Shirberg answered 31/1, 2016 at 7:22 Comment(1)
For newbies, chown -R $USER /home/aweeeezy/.cache/pip will also work.Prissie

© 2022 - 2024 — McMap. All rights reserved.