dengwirda / jigsaw-geo-python

Python bindings for JIGSAW(GEO): an unstructured mesh generator for geoscientific modelling.
Other
19 stars 10 forks source link

Missing jigsaw library on Mac #9

Closed matthewhoffman closed 4 years ago

matthewhoffman commented 5 years ago

On a Mac using jigsawpy via anaconda, I encountered this error:

>>> import jigsawpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mhoffman/anaconda/envs/compass_py3.7/lib/python3.7/site-packages/jigsawpy/__init__.py", line 64, in <module>
    from jigsawpy  import jigsaw, libsaw
  File "/Users/mhoffman/anaconda/envs/compass_py3.7/lib/python3.7/site-packages/jigsawpy/libsaw.py", line 68, in <module>
    jlib = ct.cdll.LoadLibrary(str(jlibname))
  File "/Users/mhoffman/anaconda/envs/compass_py3.7/lib/python3.7/ctypes/__init__.py", line 434, in LoadLibrary
    return self._dlltype(name)
  File "/Users/mhoffman/anaconda/envs/compass_py3.7/lib/python3.7/ctypes/__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(libjigsaw.so, 6): image not found

I traced this to the difference in library file extension used by Macs (.dylib) vs Linux (.so) platforms. I was able to fix the problem by making the following patch to differentiate the two platforms. (The current test of os.name evaluates to 'posix' for both systems.)

4c4
< import os, inspect
---
> import os, inspect, platform
40,41c40,41
<
<     if   (os.name ==    "nt"):
---
>     #print (platform.system())
>     if   (platform.system() ==    "Windows"):
45c45
<     elif (os.name == "posix"):
---
>     elif (platform.system() == "Linux"):
48a49,52
>     elif (platform.system() == "Darwin"):
>         jlibname  = \
>             filepath/"_lib"/"libjigsaw.dylib"
>
57c61
<     if   (os.name ==    "nt"):
---
>     if   (platform.system() ==    "Windows"):
60c64
<     elif (os.name == "posix"):
---
>     elif (platform.system() == "Linux"):
62a67,69
>     elif (platform.system() == "Darwin"):
>         jlibname  = Path (  "libjigsaw.dylib" )
>
67a75
>     print( jlibname )
70d77
<    #print( jlibname )
828d834
<
dengwirda commented 4 years ago

This should be fixed in https://github.com/dengwirda/jigsaw-python/commit/55d391ef07035460ef580a0b91d031754841113d.