pip install django错误

时间:2016-03-12 18:03:57

标签: python django pip

我正在尝试在终端中使用 pip 安装 django

然而,我总是得到例外。最后一个错误始终是“权限被拒绝”,我不明白为什么。任何帮助表示赞赏。

日志:

pip install django
You are using pip version 7.1.0, however version 8.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting django
  Using cached Django-1.9.4-py2.py3-none-any.whl
Installing collected packages: django
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/basecommand.py", line 223, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/commands/install.py", line 299, in run
    root=options.root_path,
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 646, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 813, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 1008, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/wheel.py", line 339, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/wheel.py", line 310, in clobber
    ensure_dir(destdir)
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/utils/__init__.py", line 70, in ensure_dir
    os.makedirs(path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/django'

3 个答案:

答案 0 :(得分:0)

sudo pip install django 

错误告诉您无法访问目录(没有足够的权限),因此您可以通过sudo获取root权限以获取权限。< / p>

答案 1 :(得分:0)

pip应由具有写入site-packages目录权限的用户运行(在您的情况下为/Library/Python/2.7/site-packages/)。您应该从root用户或sudo下运行。

答案 2 :(得分:0)

我的解决方案[Errno 13]权限被拒绝:

目标:将软件包安装到system / virtualenv

为什么会出现这个问题?  因为除了root之外,您创建的其他用户没有写入站点包的权限,这就是您为该用户拒绝操作系统错误权限的原因

如何解决?

确保您始终激活virtualenv

  

来源bin / activate

假设我创建了一个用户

(sampleEnv) sunny@ubuntu-512mb-lon1-01: pip install django

这将给出权限错误,而不是转移到root

  

$ su -

(sampleEnv) root@ubuntu-512mb-lon1-01: pip install django

现在root有权写入site-packages。

安装django后。转回用户

  

$ su - sunny

然后执行pip冻结,你可以看到系统中安装的软件包并继续!