Go Back   Computer Forums > General Computing > Programming
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 04-03-2015, 09:59 PM   #1
Beta Member
Join Date: Apr 2015
Location: United States
Posts: 3
Question Help with Python--ImportError


I'm teaching myself Python as my first programming language. The book says to type:
import urllib.request
import time

for the first two lines of code.

Whenever I type import urllib.request for the first line,
I get this error:

Traceback (most recent call last):
File "C:/Users/...", line 1, in <module>
import urllib.request
ImportError: No module named request

I'm really confused why this isn't working. I downloaded Python 3. However, when I select Run Shell, it says Python 2.7.6. I doubled checked and made sure that I downloaded Python 3 though.

Do you have any suggestions on how I can get this code to work?

angie is offline   Reply With Quote
Old 04-04-2015, 02:41 AM   #2
Fully Optimized
strollin's Avatar
Join Date: Mar 2011
Location: USA
Posts: 1,584
Default Re: Help with Python--ImportError

What folder is python installed in? If the folder is named \python2x then you have python 2.x installed, if the folder is named python3x then you have python 3 installed.

urllib.request is only available in 3, prior to that the library was simply urllib.

See here: https://docs.python.org/2/library/urllib.html

Note: The urllib module has been split into parts and renamed in Python 3 to urllib.request, urllib.parse, and urllib.error. The 2to3 tool will automatically adapt imports when converting your sources to Python 3. Also note that the urllib.request.urlopen() function in Python 3 is equivalent to urllib2.urlopen() and that urllib.urlopen() has been removed.

strollin is offline   Reply With Quote
Old 04-04-2015, 08:42 AM   #3
Beta Member
Join Date: Apr 2015
Location: United States
Posts: 3
Default Re: Help with Python--ImportError

So I checked which Python I installed, and it's 3. But your point also caused me to think about checking which version of Idle I was using. It turns out, on Windows 8 when I search for Idle, the first option it gives me is with Python 2, the second option is with Python 3. So I was chose the second option, and now it's working.
angie is offline   Reply With Quote

bugs, error, python

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 03:56 AM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0