安装请求时如何解决pip错误

时间:2019-05-30 00:07:03

标签: python ubuntu pip

我试图在Ubuntu 16.04上使用终端安装Python中的API调用请求,但出现此错误。我该如何解决?

我已经尝试过创建一个virtualenv来仅在此处安装它,但是它也不起作用。

我输入了“ pip安装请求”

Exception:
Traceback (most recent call last):

File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main status = self.run(options, args)

  File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 317, in run prefix=options.prefix_path,

  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 726, in install requirement.uninstall(auto_confirm=True)

  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 746, in uninstall paths_to_remove.remove(auto_confirm)

  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_uninstall.py", line 115, in remove renames(path, new_path)

  File "/usr/local/lib/python2.7/dist-packages/pip/utils/__init__.py", line 267, in renames shutil.move(old, new)

  File "/usr/lib/python2.7/shutil.py", line 300, in move
    rmtree(src)

  File "/usr/lib/python2.7/shutil.py", line 252, in rmtree
    onerror(os.remove, fullname, sys.exc_info())

  File "/usr/lib/python2.7/shutil.py", line 250, in rmtree
    os.remove(fullname)

OSError: [Errno 13] Permission denied: '/usr/lib/python2.7/dist-packages/idna/codec.pyc'

2 个答案:

答案 0 :(得分:0)

打开命令提示符时,请确保您open it as administrator。您可以通过以下方式执行此操作:(假设您在Windows上)

1:单击Windows键

2:输入Command Prompt

3:右键单击第一个选项,然后选择Run as Administrator

4:在出现的框中单击“是”。

所有这些之后,您应该可以使用pip install Requests并进行安装。如果这样不起作用,则可以改用此命令(仍处于管理员模式):

python -m easy_install Requests 要么 python -m pip install Requests

答案 1 :(得分:0)

尝试使用sudo关键字进行安装以进行特权评估。只要您知道自己的凭据,以下内容就可以工作。

sudo pip install requests