I have installed pygame and livewires but am getting the following error with the following short program that I got from my python book.

AttributeError: 'module' object has no attribute 'init'

# New Graphics Window
# Demonstrates creating a graphics window

from livewires import games

games.init(screen_width = 640, screen_height = 480, fps = 50)

games.Screen.mainloop()

Dani AI

Generated

Most likely causes: the imported module isn't the LiveWires version the book expects (API mismatch), a local file is shadowing the real package, or the example targets a different Python/LiveWires release. is correct that LiveWires examples in older beginner books won't always match modern installs; @mnkthompson's note about the book date is relevant. @npn’s suggestion to call the module as if it were a constructor won’t work because a module object is not callable.

Quick diagnostics (run in the same environment where the error happened) to see what actually loaded and what names exist:

import inspect
from livewires import games
print(games.__file__)
print(sorted(n for n in dir(games) if not n.startswith('_')))

If the printed path points at a local script (for example something under the working directory), rename or remove that file and delete any .pyc / pycache entries. If the path points to site-packages but the dir output contains no initialization helper, the installed LiveWires package simply doesn't expose the init function the book used — either a different release or a Python-2-era wrapper.

Fix options:

  • Remove/rename conflicting local files and restart the interpreter.
  • Install a LiveWires release that matches the book (or run the book’s examples under the same Python major version they used).
  • Switch to pygame directly (more current and maintained) — many LiveWires examples map straightforwardly to pygame calls.

Minimal pygame window template (drop-in replacement for creating a window and main loop):

import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
clock = pygame.time.Clock()
running = True
while running:
    for e in pygame.event.get():
        if e.type == pygame.QUIT:
            running = False
    screen.fill((0, 0, 0))
    pygame.display.flip()
    clock.tick(50)
pygame.quit()

Any of the diagnostic outputs above will show which path and API are actually present and point to the appropriate next step.

Recommended Answers

All 5 Replies

I have installed pygame and livewires but am getting the following error with the following short program that I got from my python book.

AttributeError: 'module' object has no attribute 'init'

# New Graphics Window
# Demonstrates creating a graphics window

from livewires import games

games.init(screen_width = 640, screen_height = 480, fps = 50)

games.Screen.mainloop()

I believe '' would only be used if you created that in a class, though never using livewires before, I believe the following code would work.

g = games(screen_width = 640, screen_height = 480, fps = 50)

Then just reuse the 'g', or any other chosen variable.

LiveWires is a pretty well dated Python course that uses a module called games as a wrapper for PyGame. It is supposed to make the use of PyGame easier for the beginner.

Looking over the module , there is no init() method, unless there is a much newer version out.

LiveWires is a pretty well dated Python course that uses a module called games as a wrapper for PyGame. It is supposed to make the use of PyGame easier for the beginner.

Looking over the module , there is no init() method, unless there is a much newer version out.

I wonder why my book "Python Programming 2nd Ed. for the absolute beginner" gave me that program. This is frustrating.

What is the publication date of the book? Perhaps it is an old book.

I suggest you simply use the module pygame directly, tell us what you want to do and show some effort, the rest of us will help. Many of us are familiar with pygame, but not with the old somewhat mind numbing livewires pygame wrapper.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.