PIP install-r: OSError: [Errno 13] permission denied
我尝试设置Django。当我运行时pip install -r requirements.txt,我得到以下异常:
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: Permission denied: '/usr/local/lib/python2.7/dist-packages/amqp-1.4.6.dist-info'
你试过sudo吗?
sudo pip install -r requirements.txt创建virtual env,激活它并安装:<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)按用户安装<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)选项。 我们真的应该停止建议使用sudo带pip install。最好先尝试一下pip install --user。如果失败,请查看此处的顶部帖子。
你不应该使用的原因sudo如下:
当您运行pip时sudo,您以root用户身份从Internet运行任意Python代码,这是一个相当大的安全风险。如果有人在PyPI上提出恶意项目并进行安装,则会授予攻击者root权限。
1. 通常,您可以使用sudo临时获取超级用户 权限,以便在系统路径上安装程序包:
sudo pip install -r requirements.txt
sudo 在此处了解更多信息。
2. 如果您不想进行系统范围的更改,可以使用该标志在每个用户的路径上安装该软件包--user。
所需要的只是:
pip install --user runloop requirements.txt
3. 最后,为了实现更精细的控制,您还可以使用virtualenv,这可能是开发环境的优秀解决方案,特别是如果您正在处理多个项目并希望跟踪每个项目的依赖关系。
激活你的virtual env后
$ my-virtualenv/bin/activate
以下命令将在virtualenv中安装软件包(而不是在系统范围的路径上):
pip install -r requirements.txt
哦哦,原来是这样
页:
[1]