pip install failing with: OSError: [Errno 13] Permission denied on directory

前端 未结 8 1460
独厮守ぢ
独厮守ぢ 2020-11-21 22:43

pip install -r requirements.txt fails with the exception below OSError: [Errno 13] Permission denied: \'/usr/local/lib/.... What\'s wrong and how d

8条回答
  •  囚心锁ツ
    2020-11-21 22:46

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

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

       sudo pip install -r requirements.txt
      

      Find more about sudo here.

      Actually, this is a bad idea and there's no good use case for it, see @wim's comment.

    2. If you don't want to make system-wide changes, you can install the package on your per-user path using the --user flag.

      All it takes is:

       pip install --user runloop requirements.txt
      
    3. Finally, for even finer grained control, you can also use a virtualenv, which might be the superior solution for a development environment, especially if you are working on multiple projects and want to keep track of each one's dependencies.

      After activating your virtualenv with

      $ my-virtualenv/bin/activate

      the following command will install the package inside the virtualenv (and not on the system-wide path):

      pip install -r requirements.txt

提交回复
热议问题