Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import urllib in Python

I would like to import urllib to use the function 'request'. However, I encountered an error when trying to download via Pycharm:

"Could not find a version that satisfies the requirement urllib (from versions: ) No matching distribution found for urllib"

I tried pip install urllib but still had the same error. I am using Python 2.7.11. Really appreciate any help

like image 574
Square9627 Avatar asked Oct 14 '16 19:10

Square9627


People also ask

Do I need to install Urllib?

urllib. request is part of the standard library and does not need installing.

Does urllib2 work in Python 3?

NOTE: urllib2 is no longer available in Python 3.


1 Answers

A few things:

  1. As metioned in the comments, urllib is not installed through pip, it is part of the standard library, so you can just do import urllib without installation.
  2. Python 3.x has a urllib.request module, but Python 2.x does not, as far as I know.
  3. The functionality that you are looking for from urllib.request is most likely contained in urllib2 (which is also part of the standard library), but you might be even better off using requests, which probably does need to be installed through pip in your case:

    pip install requests
    

    In fact, the urllib2 documentation itself recommends that you use the requests library "for a higher-level HTTP client interface" - but I am not sure what you wish to do, so it is hard to say what would be best for your particular use case.

like image 164
elethan Avatar answered Oct 13 '22 13:10

elethan