Search code examples
pythonarcade

Trying to get Python Arcade to work on Ubuntu


I have installed Python Arcade using

pip install arcade

which ran successfully.

When trying to run the example code, or even just trying to import arcade from the Python command line, I receive an error

>>> import arcade
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/brian/.local/lib/python3.8/site-packages/arcade/__init__.py", line 250, in <module>
    from .joysticks import get_game_controllers
  File "/home/brian/.local/lib/python3.8/site-packages/arcade/joysticks.py", line 1, in <module>
    import pyglet.input
  File "/home/brian/.local/lib/python3.8/site-packages/pyglet/input/__init__.py", line 179, in <module>
    from .evdev import get_devices as evdev_get_devices
  File "/home/brian/.local/lib/python3.8/site-packages/pyglet/input/evdev.py", line 509, in <module>
    class EvdevControllerManager(ControllerManager, XlibSelectDevice):
  File "/home/brian/.local/lib/python3.8/site-packages/pyglet/input/evdev.py", line 583, in EvdevControllerManager
    def get_controllers(self) -> list[Controller]:
TypeError: 'type' object is not subscriptable
>>> 

Python version is 3.8.10, and OS is Ubuntu 20.04, but I can't get past this error.


Solution

  • Based on the response from @mkrieger1, and the error being shown, I took the following steps:

    vim /home/brian/.local/lib/python3.8/site-packages/pyglet/input/evdev.py

    added a line below the other import sections at the top

    import typing

    then went to line 583 (now 584 due to adding above), and changed

    def get_controllers(self) -> list[Controller]:

    to

    def get_controllers(self) -> typing.List[Controller]:

    and the example programs are now working.

    If anyone else is in the same situation, then hopefully this is a quick fix to try.