lab2d: Error on M1 Mac (aarch64)

Hi - I’ve just bought a new Macbook Air with the M1 chip, and after much effort getting numpy and pygame to install with pip, I now run into a new problem with lab2d / pygame…

$ bazel run --config=lua5_2 -c opt dmlab2d/python:random_agent -- --level_name=clean_up

INFO: Build completed successfully, 2 total actions
pygame 2.0.1 (SDL 2.0.14, Python 3.9.1)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "/private/var/tmp/.../execroot/org_deepmind_lab2d/bazel-out/darwin-opt/bin/dmlab2d/python/random_agent.runfiles/org_deepmind_lab2d/dmlab2d/python/random_agent.py", line 27, in <module>
    from dmlab2d.python import dmlab2d
ImportError: dlopen(/private/var/tmp/.../execroot/org_deepmind_lab2d/bazel-out/darwin-opt/bin/dmlab2d/python/random_agent.runfiles/org_deepmind_lab2d/dmlab2d/python/dmlab2d.so, 2):
  Symbol not found: _png_init_filter_functions_neon
  Referenced from: /private/var/tmp/.../execroot/org_deepmind_lab2d/bazel-out/darwin-opt/bin/dmlab2d/python/random_agent.runfiles/org_deepmind_lab2d/dmlab2d/python/dmlab2d.so
  Expected in: flat namespace
 in /private/var/tmp/.../execroot/org_deepmind_lab2d/bazel-out/darwin-opt/bin/dmlab2d/python/random_agent.runfiles/org_deepmind_lab2d/dmlab2d/python/dmlab2d.so

I got several of the pygame examples running ok (eg. chimp and liquid), although “aliens” just prints Sorry, extended image module required. I’ve googled for a way to add the extended image module but I can’t find anything. Not sure if that’s related to the lab2d problem above.

Also, I’m using bazel version 4.0.0; and I am now using pyenv for managing python versions, so the location in python.BUILD is Users/<me>/.pyenv/versions/3.9.1/include/python3.9.

Sorry to raise another problem but any advice would be much appreciated! Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21

Most upvoted comments

@RacingTadpole: could you perhaps try something very simple and just add these three entries to the srcs in png.BUILD:

    src = [
        # ...
        "arm/arm_init.c",
        "arm/filter_neon_intrinsics.c",
        "arm/palette_neon_intrinsics.c",
    ],

Edit: I tried this on a Linux-on-aarch64, and that seemed to do the trick there.

If you check https://github.com/deepmind/lab2d/blob/main/bazel/png.BUILD#L6-L11, you’ll see where the config file pnglibconf.h is copied from (namely from scripts/pnglibconf.h.prebuilt). I’d start by editing that file, e.g. to enable the Neon optimizaions. If you have a functioning local build, you can just compare that against your own generated config.h.

Then, after you’ve made the edits, you will presumably start seeing new linker errors because you’re missing relevant source files. So you need to update the srcs array of the "png" library (https://github.com/deepmind/lab2d/blob/main/bazel/png.BUILD#L15-L36) to include the missing files. At the very least I expect you’ll want the files form the arm subdirectory.

This is all pretty hacky, of course, since your edits will be lost as soon as Bazel redownloads the source archive (so keep a copy of your edited config file!), but once you’ve got something that works, we can ship that in a more permanent way.