rm-hull / luma.examples

Companion repo for running examples against the luma.oled, luma.lcd, luma.led_matrix and luma.emulator display drivers.
MIT License
367 stars 140 forks source link

--display capture giving an error #152

Closed EDIflyer closed 2 years ago

EDIflyer commented 2 years ago

I've downloaded the latest version of the examples from this repository, they run fine on my ssd1306 screen However when I try to output to PNG files using the capture option (~/examples $ ./demo.py --display capture) I get the following error:

demo.py: error: argument --display/-d: invalid choice: 'capture' (choose from 'ssd1306', 'ssd1309', 'ssd1322', 'ssd1362', 'ssd1322_nhd', 'ssd1325', 'ssd1327', 'ssd1331', 'ssd1351', 'sh1106', 'ws0010', 'winstar_weh', 'linux_framebuffer')

I note that help shows the following:

--display DISPLAY, -d DISPLAY
                        Display type, supports real devices or emulators. Allowed values are:
                        ssd1306, ssd1309, ssd1322, ssd1362, ssd1322_nhd, ssd1325, ssd1327,
                        ssd1331, ssd1351, sh1106, ws0010, winstar_weh, linux_framebuffer (default:
                        ssd1306)

whereas the README.md for here shows quite a different list:

--display DISPLAY, -d DISPLAY
                        Display type, supports real devices or emulators.
                        Allowed values are: ssd1306, ssd1309, ssd1322,
                        ssd1362, ssd1322_nhd, ssd1325, ssd1327, ssd1331,
                        ssd1351, sh1106, ws0010, winstar_weh, pcd8544, st7735,
                        ht1621, uc1701x, st7567, ili9341, ili9486, hd44780,
                        max7219, ws2812, neopixel, neosegment, apa102,
                        unicornhathd, capture, gifanim, pygame, asciiart,
                        asciiblock, linux_framebuffer (default: ssd1306)

luma.core version info as follows:

:~ $ python3 -m pip show luma.core
Name: luma.core
Version: 2.3.1
Summary: A component library to support SBC display drivers
Home-page: https://github.com/rm-hull/luma.core
Author: Richard Hull
Author-email: richard.hull@destructuring-bind.org
License: MIT
Location: /usr/local/lib/python3.9/dist-packages
Requires: smbus2, pillow, deprecated, cbor2, pyftdi, RPI.GPIO, spidev
Required-by: luma.oled

luma.oled version info as follows:

:~ $ python3 -m pip show luma.oled
Name: luma.oled
Version: 3.8.1
Summary: A small library to drive an OLED device with either SSD1306, SSD1309, SSD1322, SSD1325, SSD1327, SSD1331, SSD1351, SSD1362, SH1106 or WS0010 chipset
Home-page: https://github.com/rm-hull/luma.oled
Author: Richard Hull
Author-email: richard.hull@destructuring-bind.org
License: MIT
Location: /usr/local/lib/python3.9/dist-packages
Requires: luma.core
Required-by:

The bit that's esp frustrating is I managed to get it to work a month or so ago on a different unit and I can't work out why it's not wanting to work here! Thanks in advance for any help/advice!

rm-hull commented 2 years ago

The luma.emulator package provides the capture driver. At runtime, the core enumerates which display drivers are present and dynamically constructs that list. The docs (and/or cli help) probably ought to be updated to make that clear

EDIflyer commented 2 years ago

Ahhh! Thanks @rm-hull - I must have twigged that eventually last time I did it then forgot this time! Will submit a PR re the docs.

I installed the emulator which seemed to go OK:

$ sudo -H pip3 install --upgrade luma.emulator
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting luma.emulator
  Downloading https://www.piwheels.org/simple/luma-emulator/luma.emulator-1.4.0-py2.py3-none-any.whl (27 kB)
Requirement already satisfied: luma.core>=1.14.0 in /usr/local/lib/python3.9/dist-packages (from luma.emulator) (2.3.1)
Collecting pygame
  Downloading https://www.piwheels.org/simple/pygame/pygame-2.1.2-cp39-cp39-linux_armv6l.whl (8.9 MB)
     |████████████████████████████████| 8.9 MB 75 kB/s
Requirement already satisfied: pyftdi in /usr/local/lib/python3.9/dist-packages (from luma.core>=1.14.0->luma.emulator) (0.53.3)
Requirement already satisfied: RPI.GPIO in /usr/local/lib/python3.9/dist-packages (from luma.core>=1.14.0->luma.emulator) (0.7.1a4)
Requirement already satisfied: deprecated in /usr/local/lib/python3.9/dist-packages (from luma.core>=1.14.0->luma.emulator) (1.2.13)
Requirement already satisfied: smbus2 in /usr/local/lib/python3.9/dist-packages (from luma.core>=1.14.0->luma.emulator) (0.4.1)
Requirement already satisfied: spidev in /usr/local/lib/python3.9/dist-packages (from luma.core>=1.14.0->luma.emulator) (3.5)
Requirement already satisfied: pillow>=4.0.0 in /usr/local/lib/python3.9/dist-packages (from luma.core>=1.14.0->luma.emulator) (8.4.0)
Requirement already satisfied: cbor2 in /usr/local/lib/python3.9/dist-packages (from luma.core>=1.14.0->luma.emulator) (5.4.2)
Requirement already satisfied: wrapt<2,>=1.10 in /usr/local/lib/python3.9/dist-packages (from deprecated->luma.core>=1.14.0->luma.emulator) (1.13.3)
Requirement already satisfied: pyusb!=1.2.0,>=1.0.0 in /usr/local/lib/python3.9/dist-packages (from pyftdi->luma.core>=1.14.0->luma.emulator) (1.2.1)
Requirement already satisfied: pyserial>=3.0 in /usr/local/lib/python3.9/dist-packages (from pyftdi->luma.core>=1.14.0->luma.emulator) (3.5)
Installing collected packages: pygame, luma.emulator
Successfully installed luma.emulator-1.4.0 pygame-2.1.2

$ python3 -m pip show luma.emulator
Name: luma.emulator
Version: 1.4.0
Summary: A suite of pseudo-devices for luma.core components
Home-page: https://github.com/rm-hull/luma.emulator
Author: Richard Hull
Author-email: richard.hull@destructuring-bind.org
License: MIT
Location: /usr/local/lib/python3.9/dist-packages
Requires: luma.core, pygame
Required-by:

But then when I tried to run it I was still getting a complaint about pygame not being installed?

$ ./demo.py --display capture
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/luma/emulator/device.py", line 43, in __init__
    import pygame
  File "/usr/local/lib/python3.9/dist-packages/pygame/__init__.py", line 83, in <module>
    from pygame.base import *  # pylint: disable=wildcard-import; lgtm[py/polluting-import]
ImportError: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/./demo.py", line 99, in <module>
    main()
  File "/home/pi/./demo.py", line 54, in main
    device = get_device()
  File "/home/pi/demo_opts.py", line 61, in get_device
    device = cmdline.create_device(args)
  File "/usr/local/lib/python3.9/dist-packages/luma/core/cmdline.py", line 272, in create_device
    device = Device(**vars(args))
  File "/usr/local/lib/python3.9/dist-packages/luma/emulator/device.py", line 102, in __init__
    super(capture, self).__init__(width, height, rotate, mode, transform, scale)
  File "/usr/local/lib/python3.9/dist-packages/luma/emulator/device.py", line 45, in __init__
    raise RuntimeError("Emulator requires pygame to be installed")
RuntimeError: Emulator requires pygame to be installed

So I re-ran pygame install separately (although it looks like it was correctly installed before and this just downloaded 2.1.1 in addition to 2.1.2 for some reason??)...

$ sudo -H pip3 install --upgrade pygame
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pygame in /usr/local/lib/python3.9/dist-packages (2.1.2)
Collecting pygame
  Using cached https://www.piwheels.org/simple/pygame/pygame-2.1.2-cp39-cp39-linux_armv6l.whl (8.9 MB)
  Downloading https://www.piwheels.org/simple/pygame/pygame-2.1.1-cp39-cp39-linux_armv6l.whl (8.9 MB)
     |████████████████████████████████| 8.9 MB 52 kB/s

$ python3 -m pip show pygame
Name: pygame
Version: 2.1.2
Summary: Python Game Development
Home-page: https://www.pygame.org
Author: A community project.
Author-email: pygame@pygame.org
License: LGPL
Location: /usr/local/lib/python3.9/dist-packages
Requires:
Required-by: luma.emulator

but I still get the same error of the Emulator requiring pygame to be installed?

PS the dynamically generated list from ./demo.py --help now lists it at least...

--display DISPLAY, -d DISPLAY
                        Display type, supports real devices or emulators. Allowed values are:
                        ssd1306, ssd1309, ssd1322, ssd1362, ssd1322_nhd, ssd1325, ssd1327,
                        ssd1331, ssd1351, sh1106, ws0010, winstar_weh, capture, gifanim, pygame,
                        asciiart, asciiblock, linux_framebuffer (default: ssd1306)
thijstriemstra commented 2 years ago

are you able to import pygame using that interpreter? python3 -c "import pygame" shouldn't throw any errors.

EDIflyer commented 2 years ago

Ahh, interesting @thijstriemstra it does indeed throw an error!...

$ python3 -c "import pygame"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/pygame/__init__.py", line 83, in <module>
    from pygame.base import *  # pylint: disable=wildcard-import; lgtm[py/polluting-import]
ImportError: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory

I tried running sudo -H pip3 install --upgrade --force-reinstall --ignore-installed pygame but still got the same error after when I tried to import it.

Any thoughts how to resolve? 😬

rm-hull commented 2 years ago

Did you see the prerequisites here https://luma-emulator.readthedocs.io/en/latest/install.html#system-packages ?

EDIflyer commented 2 years ago

Yes - as far as I could see they were all met? It said 'Requirements already satisfied' for them all? https://github.com/rm-hull/luma.examples/issues/152#issuecomment-1027171558

EDIflyer commented 2 years ago

OK so I uninstalled pygame and luma.emulator and reinstalled them again, this time I got a different error...

$python3 demo.py --display capture
pygame 2.1.2 (SDL 2.0.14, Python 3.9.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "/home/pi/demo.py", line 99, in <module>
    main()
  File "/home/pi/demo.py", line 54, in main
    device = get_device()
  File "/home/pi/demo_opts.py", line 61, in get_device
    device = cmdline.create_device(args)
  File "/usr/local/lib/python3.9/dist-packages/luma/core/cmdline.py", line 272, in create_device
    device = Device(**vars(args))
  File "/usr/local/lib/python3.9/dist-packages/luma/emulator/device.py", line 102, in __init__
    super(capture, self).__init__(width, height, rotate, mode, transform, scale)
  File "/usr/local/lib/python3.9/dist-packages/luma/emulator/device.py", line 49, in __init__
    self._transform = getattr(transformer(pygame, width, height, scale),
  File "/usr/local/lib/python3.9/dist-packages/luma/emulator/render.py", line 22, in __init__
    [self._pygame.image.load(str(base_dir.joinpath("images", img)))
  File "/usr/local/lib/python3.9/dist-packages/luma/emulator/render.py", line 22, in <listcomp>
    [self._pygame.image.load(str(base_dir.joinpath("images", img)))
pygame.error: File is not a Windows BMP file

After a bit more Googling I came across this from last year - https://github.com/pygame/pygame/issues/2503

I did sudo apt-get install libsdl2-image-2.0-0 and that seemed to do the trick! So I wonder if the pre-requisites need to be change from libsdl-image1.2-dev to libsdl2-image-2.0-0?

(I'm using Raspberry Pi OS bullseye in case that makes any difference)

Anyway, thanks to your both for your help (not to mention creating this excellent library in the first place!) - I've now got PNGs generating so can enhance my user guide!

rm-hull commented 2 years ago

So I wonder if the pre-requisites need to be change from libsdl-image1.2-dev to libsdl2-image-2.0-0?

quite probably

EDIflyer commented 2 years ago

OK have done a PR for that - thanks again @rm-hull and @thijstriemstra - greatly appreciate the rapid help! 👍🥳