In this session we are going to load up a  module that is missing from our Python library.

Step 1 Double click on the IDLE desktop icon and start up Python

Step 2 Click ‘file’ and open the helloworld program from session 1

Step 3 Above the print statement in the program add the following lines

import requests
import urllib
import urllib.request
import urllib.error
import json
import datetime
import sys
import time

Step 4 Run the program

Step 5 You will notice that Python complains of not having access to the requests module. We need to install this module

Step 6 Open a black MSDOS window and navigate to the Scripts folder using the cd (change directory) command. For example at the MSDOS prompt I would type in

cd c:\python34\Scripts

Step 7 Type in easy_install requests

It will probably take around a minute to download and install

Step 8 When the install has completed run the helloworld program again from within IDLE. Notice it still does not find the requests module and hence fails to run. Close the program window and the IDLE execution window and then restat the IDLE execution window and reload the program file helloworld. Picking up the requests module it should now run OK

We will need the requests module to execute http requests from our Python program, but more of that later

Advertisements