Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79187 > unrolled thread
| Started by | ryguy7272 <ryanshuell@gmail.com> |
|---|---|
| First post | 2014-10-15 17:40 -0700 |
| Last post | 2014-10-16 23:56 +0100 |
| Articles | 14 — 11 participants |
Back to article view | Back to comp.lang.python
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
| From | ryguy7272 <ryanshuell@gmail.com> |
|---|---|
| Date | 2014-10-15 17:40 -0700 |
| Subject | Import Doesn't Import |
| Message-ID | <1a3844da-b467-43ba-b34f-3aaa6442d799@googlegroups.com> |
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!!!!!
[toc] | [next] | [standalone]
| From | ryguy7272 <ryanshuell@gmail.com> |
|---|---|
| Date | 2014-10-15 17:44 -0700 |
| Message-ID | <20f25f12-d376-4b78-9fb4-e877e2fcde15@googlegroups.com> |
| In reply to | #79187 |
On Wednesday, October 15, 2014 8:40:40 PM UTC-4, 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!!!!!
Either this is the most brilliant thing ever invented, or it's the biggest piece of shit ever invented. I just can't tell. All I know for sure, is that it doesn't do ANYTHING that I tell it to do.
If there is another way of running Python code, like using Visual Studio, or a text file, or some such thing, let me know, and I'll do it. It seems like you should use Python to run Python, but my Python doesn't do anything at all. Yesterday I uninstalled Python 2.7, because that wouldn't do anything either. I'm just about ready to uninstall 3.4.
[toc] | [prev] | [next] | [standalone]
| From | Dan Stromberg <drsalists@gmail.com> |
|---|---|
| Date | 2014-10-15 18:19 -0700 |
| Message-ID | <mailman.14906.1413422379.18130.python-list@python.org> |
| In reply to | #79188 |
On Wed, Oct 15, 2014 at 5:44 PM, ryguy7272 <ryanshuell@gmail.com> wrote: > Either this is the most brilliant thing ever invented, or it's the biggest piece of shit ever invented. I just can't tell. All I know for sure, is that it doesn't do ANYTHING that I tell it to do. Maybe you should decide whether you want to run your 2.x code on 2.7, or adapt it to 3.x. Doing both won't work well, unless you go with a version of the code carefully constructed to work on both. I believe I heard there's a way of doing Python in Visual Studio, but personally, I use Python on Linux without an IDE - mostly via a vim macro. BTW, I got your code to run, but it got stuck in a socket.recv(); I suspect Wikipedia is blocking some forms of access, so this labor may be irrelevant. Perhaps check out https://pypi.python.org/pypi?%3Aaction=search&term=stock&submit=search , and use the most relevant-looking one with a matching version of Python?
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2014-10-15 22:43 -0400 |
| Message-ID | <mailman.14912.1413427419.18130.python-list@python.org> |
| In reply to | #79188 |
Perhaps you are trying too hard too fast. When I started Python, after 20 years of on and off experience with multiple languages, I went through the tutorial (on Dos, no Idle). It took about 2 hours. Then I quickly wrote the code I needed for a paid project. Do stick with 3.4.2, but use the 3.4.2 manual. On 10/15/2014 8:44 PM, ryguy7272 wrote: > Either this is the most brilliant thing ever invented, This, I think. > or it's the biggest piece of shit ever invented. Definitely not. It is possible that Python will never fit your brain. But give it a bit more of a chance. > All I know for sure, is that it doesn't do ANYTHING > that I tell it to do. Because you have told it to do things like run a program with syntax error, or import something that does not exist. I don't know of any language than does that ;-). -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-10-16 09:01 +0100 |
| Message-ID | <mailman.14914.1413446524.18130.python-list@python.org> |
| In reply to | #79188 |
On 16/10/2014 01:44, ryguy7272 wrote: If you carry on using this approach and you continue using the buggy google groups interface you're unlikely to make many friends. May I suggest that before posting you spend a few minutes doing some research as Python has been in use for 22 years so your questions have been answered many times before. > > Either this is the most brilliant thing ever invented, or it's the biggest piece of shit ever invented. I just can't tell. All I know for sure, is that it doesn't do ANYTHING that I tell it to do. A bad workman always blames his tools. > > If there is another way of running Python code, like using Visual Studio, or a text file, or some such thing, let me know, and I'll do it. It seems like you should use Python to run Python, but my Python doesn't do anything at all. Yesterday I uninstalled Python 2.7, because that wouldn't do anything either. I'm just about ready to uninstall 3.4. > https://docs.python.org/3/using/windows.html https://docs.python.org/3/using/windows.html#launcher -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-10-16 11:54 +1100 |
| Message-ID | <mailman.14902.1413420845.18130.python-list@python.org> |
| In reply to | #79187 |
On Thu, Oct 16, 2014 at 11:40 AM, ryguy7272 <ryanshuell@gmail.com> wrote: > I totally don't understand this language. Import means import. Right. WTF!!!!! Yes, but import from where? If you ask Python - or any other language - to "import asfadgt4tfihavzcxvzxcvaerg", do you expect it to succeed? It doesn't exist. In this case, you simply want "urllib", not "urllib2". You should be able to "import urllib" with no problems. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Dan Stromberg <drsalists@gmail.com> |
|---|---|
| Date | 2014-10-15 18:12 -0700 |
| Message-ID | <mailman.14904.1413421938.18130.python-list@python.org> |
| In reply to | #79187 |
On Wed, Oct 15, 2014 at 5:40 PM, ryguy7272 <ryanshuell@gmail.com> wrote: > > ImportError: No module named 'urllib2' http://stackoverflow.com/questions/2792650/python3-error-import-error-no-module-name-urllib
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2014-10-16 02:13 +0100 |
| Message-ID | <mailman.14905.1413422034.18130.python-list@python.org> |
| In reply to | #79187 |
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
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-10-16 12:35 +1100 |
| Subject | Python 3 is the active language, recommended for newcomers (was: Import Doesn't Import) |
| Message-ID | <mailman.14908.1413423345.18130.python-list@python.org> |
| In reply to | #79187 |
ryguy7272 <ryanshuell@gmail.com> writes: > So, I'm reading this link. > https://docs.python.org/2/howto/urllib2.html Note that this is the documentation for Python 2, which is obsolescent. It has had a long life, so references to Python on the web are still dominantly about that legacy version. Your confusion is quite normal. Instead, use Python 3 only (which it seems you are doing), and read the Python 3 documentation. You'll find that the ‘urllib’ modules <URL:https://docs.python.org/3/library/urllib.html> are what you want. > I don't get it; I just don't get it. It's unfortunate that a lot of new Python users will be confused by this long transition. But the situation is a lot better now; more and more Python articles on the web are referring to Python 3 which is the actively-developed version, recommended for new users. -- \ “You don't need a book of any description to help you have some | `\ kind of moral awareness.” —Dr. Francesca Stavrakoloulou, bible | _o__) scholar, 2011-05-08 | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Chris Rebert <clp2@rebertia.com> |
|---|---|
| Date | 2014-10-15 18:21 -0700 |
| Message-ID | <mailman.14909.1413424210.18130.python-list@python.org> |
| In reply to | #79187 |
[Multipart message — attachments visible in raw view] — view raw
On Wednesday, October 15, 2014, ryguy7272 <ryanshuell@gmail.com> 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
>
>
Important note!: The "/2/" in the URL means those docs are for Python 2.x
When using Python 3, ensure that the docs you're consulting have a "/3/" in
them instead.
> 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'
>
>
You're using Python 3, and the urllib2 module no longer exists in Python 3.
The URL/HTTP modules got refactored on Python 3. You want the
`urllib.request` module instead.
Although most folks nowadays use http://docs.python-requests.org/ instead,
though it's third-party and outside the std lib.
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2014-10-15 22:11 -0400 |
| Message-ID | <mailman.14910.1413425511.18130.python-list@python.org> |
| In reply to | #79187 |
On Wed, 15 Oct 2014 17:40:25 -0700 (PDT), ryguy7272 <ryanshuell@gmail.com>
declaimed the following:
>Fetching URLs
>The simplest way to use urllib2 is as follows:
>import urllib2
>response = urllib2.urlopen('http://python.org/')
>html = response.read()
>
Works fine in Python 2.7
PythonWin 2.7.5 (default, Sep 16 2013, 23:11:01) [MSC v.1500 64 bit
(AMD64)] on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for
further copyright information.
>>> import urllib2
>>> response = urllib2.urlopen("http://python.org/")
>>> html = response.read()
>>> print html
<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9">
<![endif]-->
<!--[if IE 7]> <html class="no-js ie7 lt-ie8 lt-ie9"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--><html class="no-js" lang="en" dir="ltr">
<!--<![endif]-->
<head>
>
>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!!!!!
Well, you are using Python 3.4 -- there were significant changes made
in the transition from 2.x to 3.x. 90% of the stuff you find on the web is
probably written against Python 2.x -- if the example uses
print "some stuff %s" % ("or other",)
if is 2.x, while
print("some stuff %s" % ("or other",))
if could be 2.x (the extra () don't affect 2.x print statement) but is more
likely to be 3.x (though 3.x likely is also using a different formatter
than the old % string interpolation).
The best documentation is the supplied help system -- the library
reference manual in particular. Glancing at that would reveal that 3.x does
not have a urllib2 module (and the documentation in 2.7.5 even states:
"""
Note
The urllib2 module has been split across several modules in Python 3 named
urllib.request and urllib.error. The 2to3 tool will automatically adapt
imports when converting your sources to Python 3.
"""
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Emile van Sebille <emile@fenx.com> |
|---|---|
| Date | 2014-10-16 14:29 -0700 |
| Message-ID | <mailman.14933.1413494980.18130.python-list@python.org> |
| In reply to | #79187 |
On 10/15/2014 5:40 PM, ryguy7272 wrote: > 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!!!!! So, maybe Import doesn't mean import -- perhaps you expect import to retrieve content from the web and make it importable(1). That's not what python's import does. Python's version looks for a local module to import. I'd suggest starting with the tutorial. Emile (1) which would imply execution of arbitrary code.
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2014-10-16 18:28 -0400 |
| Message-ID | <mailman.14936.1413498515.18130.python-list@python.org> |
| In reply to | #79187 |
On Thu, Oct 16, 2014 at 5:29 PM, Emile van Sebille <emile@fenx.com> wrote: > On 10/15/2014 5:40 PM, ryguy7272 wrote: >> >> 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!!!!! > > > So, maybe Import doesn't mean import -- perhaps you expect import to > retrieve content from the web and make it importable(1). That's not what > python's import does. Python's version looks for a local module to import. > > I'd suggest starting with the tutorial. > > Emile > > > (1) which would imply execution of arbitrary code. > > -- > https://mail.python.org/mailman/listinfo/python-list requests is a better choice than urllib -- Joel Goldstick http://joelgoldstick.com
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-10-16 23:56 +0100 |
| Message-ID | <mailman.14937.1413500178.18130.python-list@python.org> |
| In reply to | #79187 |
On 16/10/2014 23:28, Joel Goldstick wrote: > On Thu, Oct 16, 2014 at 5:29 PM, Emile van Sebille <emile@fenx.com> wrote: >> On 10/15/2014 5:40 PM, ryguy7272 wrote: >>> >>> 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!!!!! >> >> >> So, maybe Import doesn't mean import -- perhaps you expect import to >> retrieve content from the web and make it importable(1). That's not what >> python's import does. Python's version looks for a local module to import. >> >> I'd suggest starting with the tutorial. >> >> Emile >> >> >> (1) which would imply execution of arbitrary code. >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > requests is a better choice than urllib > To an experienced user yes, to an inexperienced OP who can't even run a Python program without help a very emphatic no. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web