Installing pygplates using numpy2.0

Hi team,

Just wondering if anyone has had any luck with installing pygplates using numpy2.0+python3.12 on macOs? Having gdal with numpy2.0 seems to be a tricky.

S

Hi @john.cannon ,

Lauren also mention the problem that pygplates would not work with numpy2.0 a few days before. Below is the error message she sent me.

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with ‘pybind11>=2.12’.

If you are a user of the module, the easiest solution will be to
downgrade to ‘numpy<2’ or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Yeah, without actually trying it, I think having gdal installed with numpy2.0 should be the solution. I will report back if nobody has had any success so far.

Thanks Sia and Michael, I hadn’t realized that you need to compile using NumPy 2.0 in order to work with both NumPy 1.x and 2.x (but it makes sense).

The next pyGPlates release (soon) will add support for wheels (ie, so you can pip install pygplates). And I’ve just ensured the wheels will always get compiled with NumPy >= 2.0. I’ll do the same for conda install pygplates before the next release. Note that you can actually use conda now (see here) but it currently only supports NumPy 1.x.

In the meantime, it might be easier to downgrade your NumPy to 1.x. I suspect it might be a little while before the majority of modules support NumPy 2.x (seeing as it was only released on June 16th). Easiest is to use conda to install pygplates (it’ll take care of all those binary dependency restrictions for you).

Hi John and Micheal,

Having a PyPI package for pygplates is the best thing that can happen. This way, we would be able to add pygplates as requirement for gadopt package (gadopt.org) and would make a lot of our user-end hassle go away. (Conda is unfortunately not supported when installing our dependencies! But Pip install works great. )

Yes, in order to be backward compatible you need to compile with numpy2.0 which on MacOS using brew was very tricky.

The work around on Mac: The tricky part is that many default brew packages use numpy1.X under the hood. So these are more or less the steps one needs to take:
1 - Install numpy2.x with brew using the head version by brew install numpy --head
2 - install a boost-python3 version that uses that numpy2.x. Unfortunately this is very tricky, because even the head version of boost-python3 using nuymy1.X. Angus Gibson at ANU found a nice solution for that by patching the boost-python3.rb formula. Happy to share that anyone needs that.
3 - Then install gdal from source by using brew install -s gdal.
Hope this all helps!

Also there are a few bugs in the published 0.36.0 tar file. Here is how I could make it work:

diff --git a/src/src/api/PyFeatureCollection.cc b/src/src/api/PyFeatureCollection.cc
index 41fe37c..a06d075 100644
--- a/src/src/api/PyFeatureCollection.cc
+++ b/src/src/api/PyFeatureCollection.cc
@@ -28,6 +28,7 @@
 #include <vector>
 #include <boost/noncopyable.hpp>
 #include <boost/optional.hpp>
+#include <boost/numeric/conversion/cast.hpp>
 #include <QString>
 
 #include "PyFeatureCollectionFileFormatRegistry.h"
@@ -47,6 +48,7 @@
 #include "utils/ReferenceCount.h"
 
 
+
 namespace bp = boost::python;
 
 
diff --git a/src/src/qt-widgets/KinematicGraphPicker.h b/src/src/qt-widgets/KinematicGraphPicker.h
index c3a34cf..5e73e00 100644
--- a/src/src/qt-widgets/KinematicGraphPicker.h
+++ b/src/src/qt-widgets/KinematicGraphPicker.h
@@ -24,6 +24,8 @@
 #ifndef KINEMATICGRAPHPICKER_H
 #define KINEMATICGRAPHPICKER_H
 
+#include <qwt_series_data.h>
+
 #include "qwt_plot_canvas.h"
 #include "qwt_plot_picker.h"
 #include "qwt_text.h"
@@ -31,7 +33,6 @@
 #include "KinematicGraphsDialog.h"
 
 class QwtPlotCurve;
-class QwtPointSeriesData;
 
 namespace GPlatesQtWidgets
 {
diff --git a/src/src/qt-widgets/KinematicGraphsDialog.h b/src/src/qt-widgets/KinematicGraphsDialog.h
index 791426c..853b078 100644
--- a/src/src/qt-widgets/KinematicGraphsDialog.h
+++ b/src/src/qt-widgets/KinematicGraphsDialog.h
@@ -26,6 +26,7 @@
 
 #include <QDialog>
 #include <QScopedPointer>
+#include <qwt_series_data.h>
 
 #include "maths/LatLonPoint.h"
 
@@ -49,7 +50,7 @@
 
 class QwtPlot;
 class QwtPlotCurve;
-class QwtPointSeriesData;
+//class QwtPointSeriesData;
 
 class QStandardItemModel;
 

Good to know pip works. Interesting about conda - yes it’s unfortunate (conda being better for binary libraries commonly found in the scientific community).

Thanks, I’m hoping that Macports will support NumPy 2.0 (here) before the next pyGPlates release. But yes, if need be, might have to use brew (or find a similar solution for Macports).

Thanks. That will be in the next release. (Also mentioned in this post)