-1

I was trying to use the Terminal on Ubuntu 16.04 to install Requests for API calls in Python and had this error. How would I go about fixing it?

I have already tried creating a virtualenv to install it only there but it did not work either.

I typed in "pip install requests"

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'
orde
  • 5,233
  • 6
  • 31
  • 33
Hakeem
  • 21
  • 5

2 Answers2

0

When you are opening the command prompt, make sure you open it as administrator. You can do this by: (assuming you are on windows)

1: Clicking the windows key

2: Typing in Command Prompt

3: Right Clicking the first option and choosing Run as Administrator

4: Clicking yes in the box that should appear.

After all of that, you should be able to use pip install Requests and install it. If that doesn't work, you can use this command instead (still in administrator mode):

python -m easy_install Requests or python -m pip install Requests

Arnav Poddar
  • 354
  • 2
  • 18
  • 1
    You can also use the command `python -m pip install Requests`. – Bryan Zeng May 30 '19 at 00:16
  • The OP is on Ubuntu, as indicated by "_I was trying to use the Terminal on Ubuntu 16.04_" and the fact that all paths start with */usr/lib*. There is no "Run as Administrator" on Ubuntu. – Gino Mempin May 30 '19 at 00:22
  • Oh, shoot. Thanks for pointing that out to me. In that case, he can use the two commands I put in the last line – Arnav Poddar May 30 '19 at 00:47
0

Try installing using the sudo keyword to give yourself privilege evaluations. The following should work as long as you know your credentials.

sudo pip install requests
Thomas Hayes
  • 102
  • 6
  • 1
    It's not recommended to be doing `sudo pip install`, using a virtualenv would have been better. See [Is it acceptable and safe to run pip install under sudo?](https://stackoverflow.com/questions/15028648/is-it-acceptable-and-safe-to-run-pip-install-under-sudo) – Gino Mempin May 30 '19 at 04:09