查看: 2105|回复: 4

PIP install-r: OSError: [Errno 13] permission denied

[复制链接]

11

主题

80

帖子

199

积分

注册会员

Rank: 2

积分
199
发表于 2018-9-18 16:54:19 | 显示全部楼层 |阅读模式
我尝试设置Django。
当我运行时pip install -r requirements.txt,我得到以下异常:
  1. 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
  2. Cleaning up...
  3. Exception:
  4. Traceback (most recent call last):
  5.   File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
  6.     status = self.run(options, args)
  7.   File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run
  8.     requirement_set.install(install_options, global_options, root=options.root_path)
  9.   File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1436, in install
  10.     requirement.install(install_options, global_options, *args, **kwargs)
  11.   File "/usr/lib/python2.7/dist-packages/pip/req.py", line 672, in install
  12.     self.move_wheel_files(self.source_dir, root=root)
  13.   File "/usr/lib/python2.7/dist-packages/pip/req.py", line 902, in move_wheel_files
  14.     pycompile=self.pycompile,
  15.   File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 206, in move_wheel_files
  16.     clobber(source, lib_dir, True)
  17.   File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 193, in clobber
  18.     os.makedirs(destsubdir)
  19.   File "/usr/lib/python2.7/os.py", line 157, in makedirs
  20.     mkdir(name, mode)
  21. OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/amqp-1.4.6.dist-info'
复制代码

回复

使用道具 举报

10

主题

72

帖子

180

积分

注册会员

Rank: 2

积分
180
发表于 2018-9-18 16:54:54 | 显示全部楼层
你试过sudo吗?
  1. sudo pip install -r requirements.txt
复制代码
创建virtual env,激活它并安装:
  1. <pre style="background:#EFF0F1;vertical-align:baseline"><span class="pln"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">virtualenv env<o:p></o:p></span></span></pre><pre style="background:#EFF0F1;vertical-align:baseline"><span class="pln"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">source env</span></span><span class="pun"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">/</span></span><span class="pln"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">bin</span></span><span class="pun"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">/</span></span><span class="pln"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">activate<o:p></o:p></span></span></pre><pre style="background:#EFF0F1;vertical-align:baseline"><span class="pln"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">pip install </span></span><span class="pun"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">-</span></span><span class="pln"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">r requirements</span></span><span class="pun"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">.</span></span><span class="pln"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">tx</span></span></pre>
复制代码

b)按用户安装
  1. <span class="pln"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">pip install </span></span><span class="pun"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">--</span></span><span class="pln"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">user </span></span><span class="pun"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">-</span></span><span class="pln"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">r requirements</span></span><span class="pun"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">.</span></span><span class="pln"><span lang="EN-US" style="font-size: 10pt; font-family: inherit, serif; color: rgb(48, 51, 54); border: 1pt none windowtext; padding: 0cm; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">txt</span></span>
复制代码

我的建议使用安全(a)选项。
回复

使用道具 举报

9

主题

74

帖子

185

积分

注册会员

Rank: 2

积分
185
发表于 2018-9-18 16:56:35 | 显示全部楼层
我们真的应该停止建议使用sudo带pip install。最好先尝试一下pip install --user。如果失败,请查看此处的顶部帖子。
你不应该使用的原因sudo如下:
当您运行pip时sudo,您以root用户身份从Internet运行任意Python代码,这是一个相当大的安全风险。如果有人在PyPI上提出恶意项目并进行安装,则会授予攻击者root权限。
回复

使用道具 举报

11

主题

63

帖子

159

积分

注册会员

Rank: 2

积分
159
发表于 2018-9-18 16:58:16 | 显示全部楼层
1.        通常,您可以使用sudo临时获取超级用户 权限,以便在系统路径上安装程序包:
  1. sudo pip install -r requirements.txt
复制代码

sudo 在此处了解更多信息。
2.        如果您不想进行系统范围的更改,可以使用该标志在每个用户的路径上安装该软件包--user。
所需要的只是:
  1. pip install --user runloop requirements.txt
复制代码

3.        最后,为了实现更精细的控制,您还可以使用virtualenv,这可能是开发环境的优秀解决方案,特别是如果您正在处理多个项目并希望跟踪每个项目的依赖关系。
激活你的virtual env后
  1. $ my-virtualenv/bin/activate
复制代码

以下命令将在virtualenv中安装软件包(而不是在系统范围的路径上):
  1. pip install -r requirements.txt
复制代码

回复

使用道具 举报

5

主题

41

帖子

108

积分

注册会员

Rank: 2

积分
108
发表于 2018-10-10 08:15:38 | 显示全部楼层
哦哦,原来是这样
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表