pip升级OSError:[Errno:13]权限被拒绝

时间:2016-12-25 14:28:16

标签: python ubuntu operating-system pip

我需要在我的Ubuntu系统上升级pip但是我收到错误:

Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Uninstalling pip-8.1.2:
      Successfully uninstalled pip-8.1.2
  Rolling back uninstall of pip
Exception:
Traceback (most recent call last):
  File "/home/shivams334/.local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/shivams334/.local/lib/python2.7/site-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/home/shivams334/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 742, in install
**kwargs
  File "/home/shivams334/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/home/shivams334/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 1032, in move_wheel_files
    isolated=self.isolated,
  File "/home/shivams334/.local/lib/python2.7/site-packages/pip/wheel.py", line 346, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/home/shivams334/.local/lib/python2.7/site-packages/pip/wheel.py", line 317, in clobber
    ensure_dir(destdir)
  File "/home/shivams334/.local/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  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/pip-9.0.1.dist-info'
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

也许我应该选择'chown',但不知道如何使用它。请帮忙。

1 个答案:

答案 0 :(得分:1)

由于您要升级系统范围的Python,因此需要使用管理员权限运行此命令:

sudo pip install -U pip

但是,我建议您不要更改/污染系统范围的Python。而是使用virtualenv:

virtualenv myapp
source myapp/bin/activate
pip install -U pip  # <- only if virtualenv is not up to date