OSError:[Errno 13]安装django时权限被拒绝

时间:2015-02-03 18:45:46

标签: python django ubuntu

我刚刚安装了ubuntu 14.04,并且我已经安装了pip和virtualenvironment但是当我尝试安装django时,我收到以下错误消息:

name@computername:/$ pip install django
Collecting django
  Using cached Django-1.7.4-py2.py3-none-any.whl
Installing collected packages: django

  Exception:
  Traceback (most recent call last):
    File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/basecommand.py", line 232, in main
      status = self.run(options, args)
    File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/commands/install.py", line 347, in run
      root=options.root_path,
    File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/req/req_set.py", line 549, in install
      **kwargs
    File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/req/req_install.py", line 740, in install
      self.move_wheel_files(self.source_dir, root=root)
    File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/req/req_install.py", line 949, in move_wheel_files
      isolated=self.isolated,
    File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/wheel.py", line 234, in move_wheel_files
      clobber(source, lib_dir, True)
    File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/wheel.py", line 205, in clobber
      os.makedirs(destdir)
    File "/usr/lib/python2.7/os.py", line 157, in makedirs
      mkdir(name, mode)
  OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/django'

当我尝试在venv上安装时,它确实有效。

这可能与$ PYTHONPATH有关吗?

(我相信当我尝试在已经启动的项目上运行runserver时,这也会导致冲突。但如果这个问题没有解决,我会留下另一个问题。)

1 个答案:

答案 0 :(得分:7)

您需要先activate您的虚拟环境。

$ source PATH_TO_ENV/bin/env
$ pip install django
  

在新创建的virtualenv中,还会有一个激活shell脚本。对于Windows系统,为命令提示符和Powershell提供了激活脚本。

     

在Posix系统上,它位于/ENV/bin/

除非你这样做,否则你使用的是系统python和系统库。这就是你看错的原因。

如果您需要在系统范围内安装lib,则需要root访问权限:

$ sudo pip install django