Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79192
| Date | 2014-10-16 02:13 +0100 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: Import Doesn't Import |
| References | <1a3844da-b467-43ba-b34f-3aaa6442d799@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14905.1413422034.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Import Doesn't Import ryguy7272 <ryanshuell@gmail.com> - 2014-10-15 17:40 -0700
Re: Import Doesn't Import ryguy7272 <ryanshuell@gmail.com> - 2014-10-15 17:44 -0700
Re: Import Doesn't Import Dan Stromberg <drsalists@gmail.com> - 2014-10-15 18:19 -0700
Re: Import Doesn't Import Terry Reedy <tjreedy@udel.edu> - 2014-10-15 22:43 -0400
Re: Import Doesn't Import Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-16 09:01 +0100
Re: Import Doesn't Import Chris Angelico <rosuav@gmail.com> - 2014-10-16 11:54 +1100
Re: Import Doesn't Import Dan Stromberg <drsalists@gmail.com> - 2014-10-15 18:12 -0700
Re: Import Doesn't Import MRAB <python@mrabarnett.plus.com> - 2014-10-16 02:13 +0100
Python 3 is the active language, recommended for newcomers (was: Import Doesn't Import) Ben Finney <ben+python@benfinney.id.au> - 2014-10-16 12:35 +1100
Re: Import Doesn't Import Chris Rebert <clp2@rebertia.com> - 2014-10-15 18:21 -0700
Re: Import Doesn't Import Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-15 22:11 -0400
Re: Import Doesn't Import Emile van Sebille <emile@fenx.com> - 2014-10-16 14:29 -0700
Re: Import Doesn't Import Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-16 18:28 -0400
Re: Import Doesn't Import Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-16 23:56 +0100
csiph-web