Panda3D on M1 Mac; problem OpenCV dynamic libraries: solved

It only requires a couple of steps but it was quite tricky, for me at least. I imagine this may be covered somewhere else but I couldn’t locate it so I thought this could be useful to others.

Panda3D was installed in the recommended way: pip install panda3d==1.10.11 but my test code produced the following error:

...
    from pandac.PandaModules import loadPrcFileData
  File "/Users/shannon/PycharmProjects/pdlgp/venv/lib/python3.8/site-packages/pandac/PandaModules.py", line 28, in <module>
    from panda3d.vision import *
ImportError: dlopen(/Users/shannon/PycharmProjects/pdlgp/venv/lib/python3.8/site-packages/panda3d/vision.cpython-38-darwin.so, 0x0002): Library not loaded: lib/libopencv_imgproc.2.4.dylib
  Referenced from: /Users/shannon/PycharmProjects/pdlgp/venv/lib/python3.8/site-packages/panda3d/libopencv_highgui.2.4.3.dylib
  Reason: tried: 'lib/libopencv_imgproc.2.4.dylib' (no such file), '/usr/local/lib/libopencv_imgproc.2.4.dylib' (no such file), '/usr/lib/libopencv_imgproc.2.4.dylib' (no such file)

Process finished with exit code 1

I wasn’t sure, until I checked the binaries, if they were native ARM or Intel run via Rosetta 2. It turns out this is all running native—Intel and ARM packaged together—so it wasn’t an architecture incompatibility, Python just couldn’t find the libraries it needed.

Initially, I tried pip installing opencv-python, the latest version of OpenCV is 4.x but Panda3D is compiled against 2.4.x. No good. Homebrew, it turns out does has a build of OpenCV 2.x and installed that:

brew install opencv@2

Brew warns that this is a legacy version and it won’t symlink the dynamic libraries into brew’s global lib directory and gives an alternate location but that is a broken symlink on my computer. Instead I exported the library’s install location with the DYLD_LIBRARY_PATH (not LD_LIBRARY_PATH like Linux) environment variable which fixed this issue:

export DYLD_LIBRARY_PATH=/opt/homebrew/Cellar/opencv@2/2.4.13.7_12.reinstall/lib/:$DYLD_LIBRARY_PATH
1 Like

Thanks for letting us know!

Note that using pandac.PandaModules is deprecated; if you had imported it from panda3d.core instead, you would have avoided this error.

I strongly recommend you use the panda3d.* modules so that you don’t import components of Panda3D that your application does not need.

My code is certainly legacy, dating back to 2008.

Note that using pandac.PandaModules is deprecated; if you had imported it from panda3d.core instead, you would have avoided this error.

Although, I can’t find where in my current code there is an import like this… Not a big issue. Anyway, a huge thanks to rdb and everybody else for keeping this project current; Panda3D is a real gem :+1:

1 Like