Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3230482
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:55:56+00:00 2026-05-17T16:55:56+00:00

I am learning Python, and I have written a script per an example in

  • 0

I am learning Python, and I have written a script per an example in the book I am reading where it imports the urllib library. This works fine when I run it from IDLE, but if I go to the folder where the file is and run “python test.py” I get an error where it tells me that

Traceback (most recent call last):
  File "test.py", line 1, in ?
    import urllib.request
ImportError: No module named request

I verified that I am using Python 3.1.2. Any suggestions or ideas why this fails on the command line?

My code:

import urllib.request
import time

price = 99.99
while price > 1.01:
    time.sleep(3)
    page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")
    text = page.read().decode("utf8")
    where = text.find('>$')
    start_of_price = where + 2
    end_of_price = start_of_price + 4
    price = float(text[start_of_price:end_of_price])

print ("Buy!")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:55:57+00:00Added an answer on May 17, 2026 at 4:55 pm

    urllib.request was introduced with Python 3. It is very possible that when you run the code from the command line, you are using an older, Python 2.x binary.

    Type python --version on the command line to see which Python is being used.

    Edit in response to Drewdin’s comment

    Running the Python 3.1.2 installer for Mac OS X, I see this:

    NOTE: This package will by default not update your shell profile and will also not install files in /usr/local. Double-click Update Shell Profile at any time to make 3.1.2 the default Python.

    The installer puts the applications in “Python 3.1”
    in your Applications folder, and the underlying machinery in
    /Library/Frameworks/Python.framework. It can optionally place
    links to the command-line tools in /usr/local as well,
    by default you have to add the “bin” directory inside
    the framework to you shell’s search path.

    So depending on how you installed it, you may already have links placed in /usr/local/bin, which will be in your path. If you chose this option at install time, all you should have to do is type python3 or python3.1 in your shell to get the updated version.

    Otherwise, either double click that “Update Shell Profile”, or add this to your path:

    export PATH=$PATH:/Library/Frameworks/Python.framework/Versions/3.1/bin

    By default, Python 3.x does not make the python command alias in Unix/Linux environments because it could possibly interfere with system processes/commands dependent on the default-installed Python.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning Python for the past few days and I have written this
I am learning python and have this error . I can figure out where\what
I have been learning python for some time now. While starting this learning python
I'm learning python. So here's what I'm after: Inside a python script I have
I'm learning Python and I have a problem with this seems to be simple
I just started using/learning Python and have some questions. I have a text file
I'm interested in learning python to have access to a more agile language for
I have just started learning python version 3 and trying to create a file
I have only started learning python recently. I would still be considered a beginner.
I have only started learning Python recently. Let me explain what I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.