python3 and macOS

Hi all,

If turn on VTK_WRAP_PYTHON on a recent version of macOS with Xcode installed, it finds:

 Python3_EXECUTABLE              */Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/bin/python3.8                                     

 Python3_INCLUDE_DIR             */Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8                                 

 Python3_LIBRARY                 */Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/libpython3.8.dylib                            

But then running tests fail with:

Library not loaded: @rpath/Python3.framework/Versions/3.8/Python3
Referenced from: /Users/builder/external/VTK-test/bin/vtkpython
Reason: tried: '/Users/builder/external/VTK-test/lib/Python3.framework/Versions/3.8/Python3' (no such file), '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/Python3.framework/Versions/3.8/Python3' (no such file), '/Users/builder/external/VTK-test/lib/Python3.framework/Versions/3.8/Python3' (no such file), '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/Python3.framework/Versions/3.8/Python3' (no such file), '/Library/Frameworks/Python3.framework/Versions/3.8/Python3' (no such file), '/System/Library/Frameworks/Python3.framework/Versions/3.8/Python3' (no such file)

I suppose I can fix this by installing my own python, but… perhaps there is something that should be fixed here?

Sean

So the above path exists in the SDK, but it doesn’t exist on the system itself? Or does it not exist in the SDK, either?

This is the “terrible rpath” issue on macOS. The library says “you need to use rpath to use me” (with the @rpath/ library id), but nothing says what path to actually add. Here, you’ll need to do it manually. See how CI does it.

I have discussed it in the CMake Discourse before (and maybe even an issue), but libraries will need an IMPORTED_RPATH property to be set so that CMake can know to add the right -Wl,-rpath, flags to the linker.

OK, that worked. Many more tests passing today. But there are still some “not run” tests saying that numpy is required:

https://open.cdash.org/test/520254656

I guess maybe the Xcode python3 doesn’t include that? I guess just installing python3 is preferable then on macOS…?

No, Xcode’s Python is (AFAIK), just the stdlib. You can make a virtualenv with the Xcode Python just fine (it’s what CI does).

So I’ve installed python from python.org then run python3 -m pip install numpy to get numpy. Many tests fail though:

https://open.cdash.org/test/531990438

with

Traceback (most recent call last):
  File "/Users/builder/external/VTK/IO/Geometry/Testing/Python/Plot3D.py", line 2, in <module>
    import vtk
ModuleNotFoundError: No module named 'vtk'

Anyone know why this might be? (I know next to nothing about how python works…)

Sean

My guess is that you installed Python 3.10, which breaks the testing due to this issue.

Bingo David! I guess I’ll downgrade to 3.9…

The downgrade to python 3.9 worked on Rogue20, so I’ve done it for all my other bots. Should be greener tomorrow.

Thanks for maintaining those bots. The CI bots don’t always catch everything.