Pip installation failed with: OSError: [Errno 13] Directory access denied

pip install -r requirements.txt fails with an exception below OSError: [Errno 13] Permission denied: '/usr/local/lib/... What is wrong and how can I fix it? (I'm trying to configure Django )

 Installing collected packages: amqp, anyjson, arrow, beautifulsoup4, billiard, boto, braintree, celery, cffi, cryptography, Django, django-bower, django-braces, django-celery, django-crispy-forms, django-debug-toolbar, django-disqus, django-embed-video, django-filter, django-merchant, django-pagination, django-payments, django-storages, django-vote, django-wysiwyg-redactor, easy-thumbnails, enum34, gnureadline, idna, ipaddress, ipython, kombu, mock, names, ndg-httpsclient, Pillow, pyasn1, pycparser, pycrypto, PyJWT, pyOpenSSL, python-dateutil, pytz, requests, six, sqlparse, stripe, suds-jurko Cleaning up... Exception: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main status = self.run(options, args) File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run requirement_set.install(install_options, global_options, root=options.root_path) File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1436, in install requirement.install(install_options, global_options, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/pip/req.py", line 672, in install self.move_wheel_files(self.source_dir, root=root) File "/usr/lib/python2.7/dist-packages/pip/req.py", line 902, in move_wheel_files pycompile=self.pycompile, File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 206, in move_wheel_files clobber(source, lib_dir, True) File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 193, in clobber os.makedirs(destsubdir) 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/amqp-1.4.6.dist-info' 
+102
python django pip install permissions
Jul 20 '15 at 8:58
source share
9 answers

Option a) Create virtualenv, activate it and install:

 virtualenv .venv source .venv/bin/activate pip install -r requirements.txt 

Option b) Install in your home directory:

 pip install --user -r requirements.txt 

My recommendation is to use the safe (a) option so that the requirements of this project do not interfere with the requirements of other projects.

+57
Jul 20 '15 at 9:02
source share
β€” -

We really should stop recommending using sudo with pip install . Better to try pip install --user . If that doesn't work, take a look at the top post here .

The reason you should not use sudo is this:

When you run pip with sudo , you run arbitrary Python code from the Internet as root, which is a pretty big security risk. If someone runs a malicious project in PyPI and you install it, you give the attacker root access to your machine.

+290
Feb 03 '17 at 10:24
source share

You are trying to install a package on a system-wide path without permission to do so.

  1. In general, you can use sudo to temporarily obtain superuser permissions on your own responsibility to install the package along a system-wide path:

     sudo pip install -r requirements.txt 

    Learn more about sudo here .

  2. If you do not want to make system-wide changes, you can install the package in your user path using the --user flag.

    All you need is:

     pip install --user runloop requirements.txt 
  3. Finally, for even more granular control, you can also use virtualenv , which can be an excellent solution for a development environment, especially if you are working on several projects and want to keep track of all the dependencies.

    After activating your virtualenv with

    $ my-virtualenv/bin/activate

    the following command installs the package inside virtualenv (and not the system-wide path):

    pip install -r requirements.txt

+25
Jul 20 '15 at 9:02
source share

Just specifying what worked for me after severe pain in Linux (based on ubuntu) refused to resolve errors when resolving, and using Bert, answer above, I now use ...

 $ pip install --user <package-name> 

or when pip starts in the requirements file ...

 $ pip install --user -r requirements.txt 

and they work reliably for every pip installation, including creating virtual environments.

However, the cleanest solution in my future experience was to install python-virtualenv and virtualenvwrapper with sudo apt-get install at the system level.

Then inside virtual environments, use pip install without the --user flag AND without sudo . Much cleaner, safer and simpler overall.

+25
May 27 '17 at 7:22
source share

The user does not have write permissions for some Python installation paths. You can give permission:

 sudo chown -R $USER /absolute/path/to/directory 

So you should give permission, then try setting it again, if you have new paths, you should also give permission:

 sudo chown -R $USER /usr/local/lib/python2.7/ 
+6
Aug 16 '17 at 13:38 on
source share

try using the sudo su command if you are using Ubuntu and then run pip install as superuser. This can help. I had the same problem and it was resolved because of this.

If you are on Windows, try running the pip install command by running the command line (cmd) as admin!

0
Nov 21 '17 at 7:26
source share

Only this command worked for me if someone had the same problem:

sudo -H / usr / local / bin / pip install --upbrade boto3

0
Dec 19 '17 at 12:41 on
source share

So, I got the exact same error for a completely different reason. Due to a completely separate but well-known Homebrew + pip error, I followed this workaround as listed in the Google Cloud help docs, where you create the .pydistutils.cfg file in your home directory. This file has a special configuration that you should only use to install certain libraries. I should have deleted this disutils.cfg file after installing the packages, but I forgot to do it. So the solution for me was really easy ...

rm ~/.pydistutils.cfg .

And then everything worked as usual. Of course, if you have some kind of configuration in this file for the real reason, you will not want to simply compose this file. But if someone else did this workaround and forgot to delete this file, it helped me!

0
Jan 22 '19 at 5:08
source share

Run chmod -0777 -r in a virtual environment and run pip install -r requirements.txt

-2
May 28 '18 at 11:29
source share



All Articles