Import Doesn't Import

MRAB python at mrabarnett.plus.com
Wed Oct 15 21:13:43 EDT 2014


On 2014-10-16 01:40, ryguy7272 wrote:
> So sorry everyone.  I've posted here several times today.  This is
> VERY frustrating.
>
 > So, I'm reading this link.
 > https://docs.python.org/2/howto/urllib2.html
 >
 >
 > Fetching URLs
 > The simplest way to use urllib2 is as follows:
 > import urllib2
 > response = urllib2.urlopen('http://python.org/')
 > html = response.read()
 >
 >
 > So, I fire up Python, and create a new file and name it and hit F5.
 >
 > All I have is thins in the file:
 > import urllib2
 > response = urllib2.urlopen('http://python.org/')
 > html = response.read()
 >
 > It immediately produces this error:
 > Traceback (most recent call last):
 >    File "C:/Python34/import_web_data.py", line 1, in <module>
 >      import urllib2
 > ImportError: No module named 'urllib2'
 >
 >
 > ImportError: No module named 'urllib2'
 > I'm telling Python to import because it doesn't exist and it throws
 > an error.  I don't get it; I just don't get it.  If I'm working with
 > R, I can import thousands of libraries with no errors whatsoever.
 > With Python, I just get thousands of errors with nothing working
 > whatsoever.  I totally don't understand this language.  Import means
 > import.  Right.  WTF!!!!!
 >
It raises an exception because there's no such module as 'urllib2' in
Python 3.

You're reading the docs here:

     https://docs.python.org/2/howto/urllib2.html

which are for Python 2, but the path you have here:

     C:/Python34/import_web_data.py

says that you're using Python 3.4.

There's an explanation of Python 2 vs Python 3 here:

https://wiki.python.org/moin/Python2orPython3



More information about the Python-list mailing list