加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-20 11:40:27 所属栏目:Python 来源:网络整理
导读:我刚刚安装了ubuntu 14.04,我已经安装了pip和virtualenvironment但是当我尝试安装 django时,我收到以下错误消息: name@computername:/$pip install djangoCollecting django Using cached Django-1.7.4-py2.py3-none-any.whlInstalling collected packages:
我刚刚安装了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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读