一尘不染

pip安装失败,出现以下错误:OSError:[Errno 13]目录上的权限被拒绝

python pip

pip install -r requirements.txt失败,但以下情况除外OSError: [Errno 13] Permission denied: '/usr/local/lib/...。有什么问题,我该如何解决?(我正在尝试设置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] Permissi

阅读 3344

收藏
2020-02-11

共2个答案

一尘不染

选项a)创建一个virtualenv,将其激活并安装:

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

选项b)安装在你的homedir中:

pip install --user -r requirements.txt
2020-02-11
一尘不染

我们真的应该停止建议sudowith 的使用pip install。最好先尝试一下pip install --user。如果失败了,请查看此处的最高职位。

你不应使用的原因sudo如下:

当你使用进行pip操作时sudo,你将以root用户身份从Internet运行任意Python代码,这会带来很大的安全风险。如果有人在PyPI上放置了一个恶意项目,然后安装了该项目,则可以使攻击者具有对计算机的根访问权限。

2020-02-11