geovista: Unable to run examples with geovista

šŸ› Bug Report

I am completely unfamiliar with GeoVista and have never used it but I was interested in making a PR with the changes here: https://github.com/bjlittle/geovista/issues/447#issuecomment-1879565162

However, after installing geovista to a clean, new environment, I am unable to run any of the examples from https://github.com/bjlittle/geovista/issues/447#issue-1901913437

How to Reproduce

pip install geovista
geovista examples --run from_unstructured__tri_hammer

This will result in an import error:

Traceback (most recent call last):
  File "/venv/bin/geovista", line 5, in <module>
    from geovista.cli import main
  File "/venv/lib/python3.12/site-packages/geovista/__init__.py", line 31, in <module>
    from .core import slice_cells, slice_lines  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/geovista/core.py", line 40, in <module>
    from .search import find_cell_neighbours
  File "/venv/lib/python3.12/site-packages/geovista/search.py", line 16, in <module>
    from pykdtree.kdtree import KDTree as pyKDTree
ImportError: dlopen(/venv/lib/python3.12/site-packages/pykdtree/kdtree.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '___kmpc_for_static_fini'

Perhaps there is a problem with pykdtree for macOS? Or maybe an issue installing with pip instead of conda?

Expected Behaviour

Some sort of output is successfully generated, likely an image.

Environment

Please share the report generated by either of the following CLI commands:

--------------------------------------------------------------------------------
  Date: Sat Jan 06

                 OS : Darwin
             CPU(s) : 8
            Machine : arm64
       Architecture : 64bit
        Environment : Python

  Python 3.12.1 (v3.12.1:2305ca5144, Dec  7 2023, 17:23:38) [Clang 13.0.0
  (clang-1300.0.29.30)]

           geovista : 0.4.0
            cartopy : 0.22.0
              click : 8.1.7
click-default-group : 1.2.4
            cmocean : 3.0.3
            netCDF4 : 1.6.5
              numpy : 1.26.3
       platformdirs : 4.1.0
              pooch : 1.8.0
           pykdtree : 1.3.10
             pyproj : 3.6.1
            pyvista : 0.43.1
           colorcet : Module not found
             sphinx : Module not found
  sphinx-copybutton : Module not found
     jupyter-sphinx : Module not found
pydata-sphinx-theme : Module not found
            codecov : Module not found
         pre-commit : Module not found
             pytest : Module not found
         pytest-cov : Module not found
        pytest-mock : Module not found

About this issue

  • Original URL
  • State: closed
  • Created 6 months ago
  • Reactions: 1
  • Comments: 23 (10 by maintainers)

Most upvoted comments

Oh you can also do pip install --no-binary pykdtree pykdtree to force the installation from source.

would it be possible for you to try installing geovista using conda or mamba on macOS instead? Does that work?

Installing from conda does not fix the issue for me, unfortunately. I get the same import error with pykdtree.

pip install pykdtree in an isolated environment, then try python -c "from pykdtree.kdtree import KDTree as pyKDTree"

This also generates the same error. So not likely not a geovista issue then, it seems! Iā€™ll close this issue accordingly.

Iā€™ll have to look into it further/elsewhereā€¦ seems like it may have something to do with incompatible pre-compiled C++ libraries with the M1 chip used in macs.

Iā€™ve created an issue and pinned it here: https://github.com/storpipfugl/pykdtree/issues/106

@bjlittle Yeah Iā€™m not confident updating the macos version would do anything. Neither the macos-11 nor the 12 image documentation say anything about OpenMP, but some dependency is bringing it in and it is found by pykdtree at build time in the CI.

As far as a hit to the macos/pykdtree community for removing that wheel, that suggests that in your experience most users donā€™t have compilers installed and ready to use on macos, right? Thatā€™s the thing I either:

  1. Always require the user to build from source on macos (requires a compiler)
  2. Provide a no OpenMP version which will install, but not perform as well as it could and users might expect.
  3. Keep the OpenMP-based wheel and have some users run into runtime issues if they donā€™t have OpenMP installed.

I just donā€™t feel super good about any of those.

@bjlittle Yes very likely. I think the bigger question is if I should just drop the pykdtree wheels for mac from PyPI. I could tell them to be built without openmp, but then you never get openmp performance from pykdtree on mac (unless you do the same --no-binary trick).

If I remove the wheels and donā€™t generate them anymore then you, the user, donā€™t need to do any special installation instructions except you need to have a compiler locally that can build pykdtree.

@djhoese @Minerallo @user27182 Brilliant, thanks!

Glad that we managed to find a pattern that works šŸ„³

When people come together like this, it reminds me of how much I love open-source software and the ecosystem we live in šŸ˜

Iā€™m just spinning up the geovista docs, so Iā€™ll see if there is an appropriate place to document this behaviour for macOS arm64 users.

@djhoese Is this pattern worth sharing over on pykdtree for the macOS arm64 users?

I would have thought -U for upgrading would have had a similar result, but I suppose if the version number is the same maybe it doesnā€™t automatically reinstall.

I tested with --upgrade as well and found that it isnā€™t sufficient and would still produce the error (likely due to the same version number, as you mention).

Note that in my testing I was also running pip cache purge before installing pykdtree.

I would have thought -U for upgrading would have had a similar result, but I suppose if the version number is the same maybe it doesnā€™t automatically reinstall. Good to know. Thanks for testing.

pip install --no-binary pykdtree pykdtree worked for me too. I wasnā€™t prompted to install a compiler, perhaps I have one already installed ?

One issue Iā€™ve found with this though is that if you run this command in an environment where pykdtree is already installed, it will not be updated, e.g.

pip install pykdtree
pip install --no-binary pykdtree pykdtree
python -c "from pykdtree.kdtree import KDTree"

will still yield

ImportError: dlopen(/venv/lib/python3.12/site-packages/pykdtree/kdtree.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '___kmpc_for_static_fini'

And so adding the --force-reinstall flag is probably a more robust solution. Installing this way fixes the import error, e.g.:

pip install pykdtree
pip install --no-binary pykdtree --force-reinstall pykdtree
python -c "from pykdtree.kdtree import KDTree"

And so the specific fix to address the bug reported in my initial post may be:

pip install --no-binary pykdtree --force-reinstall pykdtree
pip install geovista
geovista examples --run from_unstructured__tri_hammer

which will run without issue and output an image as expected.

I tried the force installation from the source using pip install --no-binary pykdtree pykdtree, Successfully installed pykdtree-1.3.10 and it worked fine when importing geovista šŸ‘ I would prefer to not mess with brew and openMP right now, sorry ^^ā€™

Yes. I thought I had fixed this. The mac wheels for arm are being built with OpenMP support. If a user installs pykdtree without a system-level OpenMP installation (ex. homebrew) then youā€™ll get error/exceptions like this. The alternative is to require users to have compilers and not distribute ARM wheels for pykdtree. Let me know what you think.

The current workaround I believe, if you have homebrew, is to do brew install omp.

Hi, I am trying to use Geovista for the first time on a Mac M2 and ran into the same problem, It seems that what fixed it is to install older version of pykdtree so I tried with pykdtree 1.3.10 and pykdtree 1.3.9 but it didnā€™t work, finally it worked with pykdtree 1.3.7.post0 (using pip install pykdtree==1.3.7.post0).

Iā€™ll provide an update here if I do ever find out what the problem was/is.

As an aside related to macOS testing, if youā€™d like to test GeoVista with macOS (or even Windows), I think it should be possible to update PyVistaā€™s integration test workflow accordingly, i.e. make a PR with changes to https://github.com/pyvista/pyvista/blob/main/.github/workflows/integration-tests.yml