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

我刚刚安装了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时,这也会导致冲突.但如果这个问题没解决,我会留下另一个问题.)

最佳答案 您首先需要
activate您的虚拟环境.

$source PATH_TO_ENV/bin/env
$pip install django

In a newly created virtualenv there will also be a activate shell script. For Windows systems, activation scripts are provided for the Command Prompt and Powershell.

On Posix systems, this resides in /ENV/bin/

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

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

$sudo pip install django
点赞