glumpy icon indicating copy to clipboard operation
glumpy copied to clipboard

Apple Silicon?

Open patrickbryant opened this issue 3 years ago • 11 comments

I'm attempting to run a glumpy script I developed in x86 on a new M1 Pro MacBook with python compiled for arm64e. It seems the triangle dependency is going to prevent me from doing this. Any workarounds/suggestions?

Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:05:16) 
[Clang 12.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import glumpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/glumpy/__init__.py", line 8, in <module>
    from . import api
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/glumpy/api/__init__.py", line 5, in <module>
    from . import matplotlib
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/glumpy/api/matplotlib/__init__.py", line 5, in <module>
    from . figure import Figure
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/glumpy/api/matplotlib/figure.py", line 6, in <module>
    from . axes import Axes
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/glumpy/api/matplotlib/axes.py", line 7, in <module>
    from glumpy.graphics.collections import PointCollection
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/glumpy/graphics/collections/__init__.py", line 11, in <module>
    from . polygon_collection import PolygonCollection
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/glumpy/graphics/collections/polygon_collection.py", line 6, in <module>
    from .raw_polygon_collection import RawPolygonCollection
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/glumpy/graphics/collections/raw_polygon_collection.py", line 6, in <module>
    import triangle
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/triangle/__init__.py", line 13, in <module>
    from .tri import (
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/triangle/tri.py", line 1, in <module>
    from .core import triang
ImportError: dlopen(/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/triangle/core.cpython-38-darwin.so, 0x0002): tried: '/core.cpython-38-darwin.so' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib//core.cpython-38-darwin.so' (no such file), '/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/triangle/core.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))

patrickbryant avatar May 06 '22 19:05 patrickbryant

Can you try to install the triangle library and check if it's running ok?

rougier avatar May 07 '22 22:05 rougier

This was with triangle installed but it is x86 which is the issue:

Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:05:16) 
[Clang 12.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import triangle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/triangle/__init__.py", line 13, in <module>
    from .tri import (
  File "/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/triangle/tri.py", line 1, in <module>
    from .core import triang
ImportError: dlopen(/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/triangle/core.cpython-38-darwin.so, 0x0002): tried: '/core.cpython-38-darwin.so' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib//core.cpython-38-darwin.so' (no such file), '/Users/patrickbryant/miniforge3/envs/py38/lib/python3.8/site-packages/triangle/core.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))

patrickbryant avatar May 12 '22 19:05 patrickbryant

I do not have a M1 (yet) so it might be a it difficult to debug. My advice would be to look at other libraires to check how people solved the X86/M1 problem/

rougier avatar May 13 '22 18:05 rougier

triangle is broken on Apple Silicon which makes glumpy unusable on the platform. I have tried compiling triangle for apple silicon, but the python wrapper code triggers compilation errors. As a result, glumpy is also completely unusable on Apple Silicon which is a shame since it is great!

david-rokeby avatar Nov 01 '22 02:11 david-rokeby

I was able to get this working on my M1 Macbook Pro, using python 3.10(.3) installed via pyenv. The trick seems to be just to install the packages from source rather than rely on wheels. I did something like the following:

git clone --recurse-submodules https://github.com/drufat/triangle
cd triangle && python setup.py install

cd .. && git clone https://github.com/glumpy/glumpy
cd glumpy && python setup.py install

At this point the package compiled but running python3 -c "import glumpy failed with a freetype error. I have freetype installed through homebrew, and for some reason it doesn't add the library directories to PATH. So it seems something like the following is needed:

DYLD_LIBRARY_PATH=$(brew --prefix freetype)/lib:$DYLD_LIBRARY_PATH python examples/hello-world.py

calvin-sykes avatar Nov 27 '22 17:11 calvin-sykes

Coudl you make a README-osx-M1.txt to explain your workaround?

rougier avatar Nov 28 '22 08:11 rougier

sure: PR is #307

calvin-sykes avatar Nov 28 '22 15:11 calvin-sykes

Great to see there is a solution! I have tried implementing @calvin-sykes's workaround but am running into the following issue:

Installed /Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.9/site-packages/triangle-20220202-py3.9-macosx-11.0-arm64.egg
Processing dependencies for triangle==20220202
Searching for triangle==20220202
Reading https://pypi.org/simple/triangle/
/Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.9/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning:  is an invalid version and will not be supported in a future release
  warnings.warn(
/Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.9/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 2013.01.06.linux-x86-64 is an invalid version and will not be supported in a future release
  warnings.warn(
/Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.9/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: x86-64 is an invalid version and will not be supported in a future release
  warnings.warn(
No local packages or working download links found for triangle==20220202
error: Could not find suitable distribution for Requirement.parse('triangle==20220202')

Any ideas? If I ignore this and try installing again it seems to work but I am unable to import triangle (here I was trying again using python 3.10):

Python 3.10.3 (main, Mar 28 2022, 04:25:36) [Clang 12.0.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import triangle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.10/site-packages/triangle-20220202-py3.10-macosx-11.1-arm64.egg/triangle/__init__.py", line 13, in <module>
    from .tri import (
  File "/Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.10/site-packages/triangle-20220202-py3.10-macosx-11.1-arm64.egg/triangle/tri.py", line 1, in <module>
    from .core import triang
ImportError: dlopen(/Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.10/site-packages/triangle-20220202-py3.10-macosx-11.1-arm64.egg/triangle/core.cpython-310-darwin.so, 0x0002): tried: '/Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.10/site-packages/triangle-20220202-py3.10-macosx-11.1-arm64.egg/triangle/core.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

From what I can tell it seems to be trying to install an x86 version of triangle despite everything else being arm64.

Perhaps an issue with command line tools which for some reason seems to have clang 14 in x86...

(glumpy) patrickbryant@Patricks-MacBook-Pro-4 projects % clang --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: x86_64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

patrickbryant avatar Dec 17 '22 16:12 patrickbryant

Ok I had accidentally been running the x86 version of the zsh shell. I switched back to the arm version, reinstalled the xcode command line tools and reinstalled triangle for source. I still get an error the first time I try installing triangle:

Installed /Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.10/site-packages/triangle-20220202-py3.10-macosx-11.1-arm64.egg
Processing dependencies for triangle==20220202
Searching for triangle==20220202
Reading https://pypi.org/simple/triangle/
/Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.10/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning:  is an invalid version and will not be supported in a future release
  warnings.warn(
/Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.10/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 2013.01.06.linux-x86-64 is an invalid version and will not be supported in a future release
  warnings.warn(
/Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.10/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: x86-64 is an invalid version and will not be supported in a future release
  warnings.warn(
No local packages or working download links found for triangle==20220202
error: Could not find suitable distribution for Requirement.parse('triangle==20220202')

but when I run the install script again it seems to work:

Processing dependencies for triangle==20220202
Searching for numpy==1.23.4
Best match: numpy 1.23.4
Adding numpy 1.23.4 to easy-install.pth file
Installing f2py script to /Users/patrickbryant/miniforge3/envs/glumpy/bin
Installing f2py3 script to /Users/patrickbryant/miniforge3/envs/glumpy/bin
Installing f2py3.10 script to /Users/patrickbryant/miniforge3/envs/glumpy/bin

Using /Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.10/site-packages
Finished processing dependencies for triangle==20220202
(glumpy) patrickbryant@Patricks-MacBook-Pro-4 triangle % cd ../
(glumpy) patrickbryant@Patricks-MacBook-Pro-4 projects % python
Python 3.10.3 (main, Mar 28 2022, 04:25:36) [Clang 12.0.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import triangle
>>> 

Unfortunately the glumpy install fails:

Installed /Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.10/site-packages/glumpy-1.1.1-py3.10-macosx-11.1-arm64.egg
Processing dependencies for glumpy==1.1.1
Searching for glumpy==1.1.1
Reading https://pypi.org/simple/glumpy/
/Users/patrickbryant/miniforge3/envs/glumpy/lib/python3.10/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning:  is an invalid version and will not be supported in a future release
  warnings.warn(
No local packages or working download links found for glumpy==1.1.1
error: Could not find suitable distribution for Requirement.parse('glumpy==1.1.1')

and if I try ignoring this and running the install script again like I did with triangle it fails:

...
triangle/core.c:19953:5: error: expression is not assignable
    --Py_REFCNT(o);
    ^ ~~~~~~~~~~~~
...
13 warnings and 6 errors generated.
error: Setup script exited with error: command '/usr/bin/clang' failed with exit code 1

At least now clang is arm64:

(glumpy) patrickbryant@Patricks-MacBook-Pro-4 Documents % which clang
/usr/bin/clang
(glumpy) patrickbryant@Patricks-MacBook-Pro-4 Documents % clang --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

patrickbryant avatar Dec 17 '22 17:12 patrickbryant

I have returned to this hoping a few months distance would get things working.

Here are my steps:

> conda create -n glumpy python=3.10.3 freetype numpy Cython PyOpenGL
> conda activate glumpy
> git clone --recurse-submodules https://github.com/drufat/triangle
> cd triangle
> python setup.py install
> cd ../
> rm -rf triangle
> git clone https://github.com/glumpy/glumpy
> cd glumpy
> python setup.py install
> cd ../
> rm -rf glumpy
> export DYLD_LIBRARY_PATH=$(freetype-config --prefix)/lib:$DYLD_LIBRARY_PATH

At this point when I try to import glumpy it complains about not being able to find libffi.7.dylib. Indeed there is no libffi.7.dylib that I can find but there is a libffi.8.dylib so I just copied it:

> cp /Users/patrickbryant/miniforge3/envs/glumpy/lib/libffi.8.dylib /Users/patrickbryant/miniforge3/envs/glumpy/lib/libffi.7.dylib

And now I can import glumpy and everything seems to work!

patrickbryant avatar Jun 22 '23 22:06 patrickbryant

Looks like the GitHub version of triangle is fine (not updated on PyPI yet), I managed to install by removing the triangle requirement from setup.py and then installing triangle with: pip install git+https://github.com/drufat/triangle.git I would guess that pre-installing triangle as above will not require removing the dependency from setup as I did?

colormotor avatar Oct 23 '23 10:10 colormotor