OSError:[Errno 13]安装Django时权限被拒绝 [英] OSError: [Errno 13] Permission denied when installing django

查看:71
本文介绍了OSError:[Errno 13]安装Django时权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am on ubuntu 14.04 freshly installed, and I have installed pip and virtualenvironment but when I try to install django I get the following error message:

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上安装时可以使用.

It does, however work when I try installing on a venv.

这与$ PYTHONPATH有什么关系吗?

Could this have anything to do with $PYTHONPATH?

(我相信,当我尝试在已经启动的项目上运行runserver时,这也会引起冲突.但是如果这个问题无法解决,我将把它留给另一个问题.)

(I believe this is also causing conflicts when I try to run runserver on an already started project. But I will leave that for another question if this one doesn't resolve it.)

推荐答案

您需要激活首先是您的虚拟环境.

You need to activate your virtual environment first.

$ source PATH_TO_ENV/bin/env
$ pip install django

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

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.

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

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

除非您执行此操作,否则您将使用系统python和系统库.这就是为什么您看到此错误.

Unless you do this you are using system python and system libs. That's why you see the error.

如果需要将lib安装到系统范围中,则需要root访问权限:

If you need to install a lib into the system scope you need root access:

$ sudo pip install django

这篇关于OSError:[Errno 13]安装Django时权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆