Q:

How to fix ''AttributeError: module 'pyglet.text' has no attribute 'label'" error in python

I am attempting to create a simple game with pyglet. I am still learning this library and am using the pyglet Programming guide to learn. However, I get the 

AttributeError: module 'pyglet.text' has no attribute 'label'

error every time I run the code. 
I have tried import pyglet.text and import pyglet.text.label. import pyglet.text still gives 

AttributeError: module 'pyglet.text' has no attribute 'label'. 

However, import pyglet.text.label gives

ModuleNotFoundError: No module named 'pyglet.text.label'.

My code is:
import pyglet
import pyglet.text.label

window = pyglet.window.Window()
label = pyglet.text.label('Hello World',
    font_name='Times New Roman',
    font_size=36,
    x=window.width//2,
    y=window.height//2,
    anchor_x='center',
    anchor_y='center')
@window.event
def on_draw():
    window.clear()
    label.draw()
pyglet.app.run()

I expected to see the window cleared to the default background color with Hello World printed on-screen. But I always get a blank window with 

AttributeError: module 'pyglet.text' has no attribute 'label' 

printed in the shell.

A:

AttributeError: module 'pyglet.text' has no attribute 'label'

You are getting this error because you are using pyglet.text.label instead of  pyglet.text.Label.
Here is the documentation to text
Import only pyglet then change label to Label and it should work.

