Try this:
from direct.gui.OnscreenImage import OnscreenImage
class world:
def __init__(self):
imageObject = OnscreenImage(image = 'images/ridge_racer_menu.jpg', pos = (0, 0, 0))
taskMgr.doMethodLater(5.0, image.destroy, 'destroyMyImage', extraArgs=[])
Hint: always import your modules at the top of your file, never inside a class or function definition.