Install prerequisites for Watson services

You won’t need the Watson services until you start using them, but you should install them now so that you’re ready to use them later.

    1. Create the package that allows your application to make REST calls:
      projwatson > pip install requests
    2. Install the Watson developer cloud SDK:
      projwatson > pip install watson-developer-cloud
    3. Create a runtime.txt file. Its contents must specify the Python version that you want on Bluemix. The sample file for this lab contains this version:
      python-3.4.3
    4. Create a requirements.txt file to tell Bluemix which package prerequisites to install for your application:projwatson> pip freeze > requirements.txtThe sample file for this lab contains these requirements:Django==1.8.5

      requests==2.8.1

      watson-developer-cloud==0.1.9

      Your project directory should look something like this:

 

  1. Set up application logging. You might prefer to use application logging rather than print commands. By using Python logging, you can keep all logging statements in the code and control how much information is logged.
    a. Edit the settings.py file, which is in the projwatson\projwatson folderb. Add the code from one of the following two options to the settings.py file. Both options do the same thing: they set the application level logging. You can set log levels to DEBUG, INFO, WARNING, ERROR, or CRITICAL.

    Option 1: Works with Python 2 and Python 3

    import logging
    logging.basicConfig(
    format='%(asctime)s:%(name)s:%(levelname)s:%(message)s',
    datefmt='%m/%d/%Y %I:%M:%S',
    level=logging.DEBUG)

    Option 2: Works with Python 3, is the more flexible, and the recommended option when you use Python 3LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
    'ourFormatter': {
    'format': '%(asctime)s:%(name)s:%(levelname)s:%(message)s',
    'datefmt': '%m/%d/%Y %I:%M:%S',
    },
    },
    'handlers': {
    'theConsole': {
    'class': 'logging.StreamHandler',
    'formatter': 'ourFormatter',
    },
    },
    'root': {
    'level': 'DEBUG',
    'handlers': ['theConsole'],
    },
    }