Can't import panda3d with Homebrew python on Mac

When installing Panda using the SDK packages on Mac, it can not be imported when using python3 installed with Homebrew.

Panda detects that Python 3 is installed and install Python 3 bindings (3.7 in this case), but then import fails with the usual error :

ModuleNotFoundError: No module named 'panda3d'

The problem is that the pth file for Python3 is installed assuming /Library/Frameworks//Python.framework/Versions/3.7 as sys.prefix

Or Homebrew uses /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7 as sys.prefix.

Simply copying /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Panda3D.pth into /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (which is a symlink to /usr/local/lib/python3.7/site-packages) solves the problem.

A nice feature would be that the SDK installer could detect the Homebrew version and copy the pth file into /usr/local/lib/python3.7/site-packages

Which version of Panda3D is this? I vaguely recall that a similar issue was fixed:

Is the fix not sufficient for Homebrew? I suppose we could simply add to the list of paths that we write the .pth file to.

It’s with 1,.10.4.1 so the fix is in. It seems that Homebrew ignores what is in /Library (which actually makes sense)

OK, I guess we can add something to /usr/local/lib/python3.7/site-packages. Out of curiosity, can you print the full sys.path?

Here they are :

$ python3 -c 'import sys; print(sys.prefix); print(sys.path)'

/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7
['', '/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages', '/Developer/Panda3D']

Edit: Just to clarify, the ‘/Developer/Panda3D’ entry in sys.path is due to Panda3D.pth in /usr/local/lib/python3.7/site-packages

My bad, I forgot to create the issue in the bug tracker, here it is : https://github.com/panda3d/panda3d/issues/755