# python3 and macOS

**URL:** https://discourse.vtk.org/t/python3-and-macos/6912
**Category:** Development
**Created:** [October 18, 2021, 7:12pm UTC](https://discourse.vtk.org/t/python3-and-macos/6912 "2021-10-18T19:12:28Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![seanm](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/a88e4f/32.png) [@seanm](https://discourse.vtk.org/u/seanm)
#### Post date: [October 18, 2021, 7:12pm UTC](https://discourse.vtk.org/t/python3-and-macos/6912/1 "2021-10-18T19:12:28Z")

</div>

Hi all,

If turn on VTK\_WRAP\_PYTHON on a recent version of macOS with Xcode installed, it finds:

```auto
 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:

```auto
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

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 18, 2021, 8:33pm UTC](https://discourse.vtk.org/t/python3-and-macos/6912/2 "2021-10-18T20:33:40Z")

</div>

> [@seanm](#):
>
> `/Library/Frameworks/Python3.framework/Versions/3.8/Python3`

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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [October 18, 2021, 10:28pm UTC](https://discourse.vtk.org/t/python3-and-macos/6912/3 "2021-10-18T22:28:48Z")

</div>

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](https://gitlab.kitware.com/vtk/vtk/-/blob/cf341212cdd0989c9ac19ffc1f77a7d24eaeb02a/.gitlab/ci/configure_macos.cmake#L25-27).

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.

---

<div class="post-metadata">

### Author: ![seanm](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/a88e4f/32.png) [@seanm](https://discourse.vtk.org/u/seanm)
#### Post date: [October 21, 2021, 2:26pm UTC](https://discourse.vtk.org/t/python3-and-macos/6912/4 "2021-10-21T14:26:27Z")

</div>

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](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…?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [October 21, 2021, 3:59pm UTC](https://discourse.vtk.org/t/python3-and-macos/6912/5 "2021-10-21T15:59:27Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![seanm](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/a88e4f/32.png) [@seanm](https://discourse.vtk.org/u/seanm)
#### Post date: [November 4, 2021, 8:31pm UTC](https://discourse.vtk.org/t/python3-and-macos/6912/6 "2021-11-04T20:31:09Z")

</div>

So I’ve installed python from [python.org](http://python.org) then run `python3 -m pip install numpy` to get numpy. Many tests fail though:

[https://open.cdash.org/test/531990438](https://open.cdash.org/test/531990438)

with

```auto
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

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 4, 2021, 8:37pm UTC](https://discourse.vtk.org/t/python3-and-macos/6912/7 "2021-11-04T20:37:49Z")

</div>

My guess is that you installed Python 3.10, which breaks the testing due to [this issue.](https://gitlab.kitware.com/vtk/vtk/-/issues/18317)

---

<div class="post-metadata">

### Author: ![seanm](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/a88e4f/32.png) [@seanm](https://discourse.vtk.org/u/seanm)
#### Post date: [November 4, 2021, 8:43pm UTC](https://discourse.vtk.org/t/python3-and-macos/6912/8 "2021-11-04T20:43:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![seanm](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/a88e4f/32.png) [@seanm](https://discourse.vtk.org/u/seanm)
#### Post date: [November 5, 2021, 4:06pm UTC](https://discourse.vtk.org/t/python3-and-macos/6912/9 "2021-11-05T16:06:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 5, 2021, 4:24pm UTC](https://discourse.vtk.org/t/python3-and-macos/6912/10 "2021-11-05T16:24:34Z")

</div>

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