Pygplates installation macOS

Hi,

I am trying to install pygplates on my MacBook with Apple M1 chip but I have trouble running it. It seems python can find it using:

import sys

sys.path.insert(1, "/Applications/GPlates/pygplates")

import pygplates

However, when then trying to use a pygplates function I run into the problem that python cannot import the pygplates package. I receive either a “module not found error” or an “import error”. In the latter case pygplates.so is recognised but it is stated that it has the wrong architecture. I tried using both the native Apple terminal and the Rosetta terminal.

Is there anyone aware how to install pygplates on a Mac with the M1 chip?

Many thanks,
Thomas

Import error message:

File “<stdin>“, line 1, in <module>
ImportError: dlopen(/Applications/Gplates/pygplates/pygplates.so, 2): no suitable image found.  Did find:
        /Applications/Gplates/pygplates/pygplates.so: mach-o, but wrong architecture
        /Applications/GPlates/pygplates/pygplates.so: mach-o, but wrong architecture

Hi Thomas,

Can you tell me the output of file $(which python) run from within the same Python environment that failed?

By the way, does GPlates work on your M1? It’s my understanding that, even though GPlates is compiled for Intel, it should still run due to translation performed by Rosetta. I had hoped the same would apply to pyGPlates, but looks like it doesn’t (since, unlike GPlates, we don’t control the application and all its dependencies; ie, the Python interpreter and other imported C-extension modules like NumPy).

Hi John,

Thanks for your reply. I checked every possible solution last night and in the end I found a workaround!

So for starters, GPlates (2.3) is working fine on my laptop. I have Rosetta 2 installed.

On to python: I’m using python 3.8.12 (64-bit). I tried to import pygplates into a .py script using sys.path.insert and PYTHONPATH. Both returned the same error.

Now here’s the funny workaround: if you use a jupyter notebook (.ipynb) instead of a regular .py script, pygplates is imported without any issues. For my purposes it doesn’t matter if I use .py or .ipynb, so that solved it for me. Perhaps this would be good to include in the pygplates documentation since I presume there will be more and more pygplates users using Mac M1 chips in the future.

Cheers,
Thomas

Hi Thomas,

Thanks for that (and confirming that GPlates works on M1).

I will probably still need to sort out the different architectures for pyGPlates at some stage (ie, compile for arm64 and x86_64), so I’m interested to know if you started jupyter notebook using the same Python environment as before? And if you could show the output of file $(which python) that’d be great, thanks - that is for any Python environment you used (although maybe you’re using the same environment both with and without jupyter, I’m not sure).

Hi John,

Sorry, forgot to answer that question. The python environment (with python 3.8.12) I used for running both the .py as well as the .ipynb script returns Mach-O 64-bit executable x86_64 when entering file $(which python). Which is interesting, because my Mac M1 uses arm64 and I’m not opening my terminal with Rosetta. I might look into this later.
I will let you know if I run into other problems and other things related to (py)GPlates on Mac M1.

Cheers,
Thomas