Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Apple Silicon arm64 architecture in pip wheels #1377

Closed
mlaves opened this issue Apr 14, 2021 · 20 comments
Closed

Support for Apple Silicon arm64 architecture in pip wheels #1377

mlaves opened this issue Apr 14, 2021 · 20 comments
Milestone

Comments

@mlaves
Copy link

mlaves commented Apr 14, 2021

I was able to successfully compile SimpleITK from source on a new Apple Silicon M1 CPU, including Python wrapping. However, installing from pypi using pip fails.

Steps to reproduce:

  • Apple MacBook Air 2020 with M1 CPU
  • macOS 11.2.3
  • Miniforge3-MacOSX-arm64
conda create --name sitk python=3.8
conda activate sitk
conda install scikit-build
CC=clang CXX=clang++ pip install simpleitk

It fails with the following error:

Undefined symbols for architecture arm64:
      "_png_init_filter_functions_neon", referenced from:
          _itk_png_read_filter_row in libitkpng-4.13.a(pngrutil.c.o)
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

Full output attached:
sitk_pip_apple_silicon.log.zip

@giuseppefilitto
Copy link

I also want to know how to install SimpleITK on my Apple MacBook Pro 2020 with M1 CPU. I can't even build it

@mlaves
Copy link
Author

mlaves commented Apr 20, 2021

@giuseppefilitto Steps to build SimpleITK with Python wrapping:

I assume that you have Xcode command line tools, homebrew and your Python environment (e.g. miniforge3) installed and configured.

brew install cmake
conda create --name sitk python=3.8
conda activate sitk
git clone https://github.com/SimpleITK/SimpleITK.git
mkdir SimpleITK-build
cd SimpleITK-build
CC=clang CXX=clang++ cmake \
  -DBUILD_EXAMPLES=OFF \
  -DBUILD_TESTING=OFF \
  -DWRAP_PYTHON=ON \
  -DWRAP_CSHARP=OFF \
  -DWRAP_JAVA=OFF \
  -DWRAP_LUA=OFF \
  -DWRAP_R=OFF \
  -DWRAP_RUBY=OFF \
  -DWRAP_TCL=OFF \
  ../SimpleITK/SuperBuild
make -j8  # build SimpleITK
make -C SimpleITK-build dist  # build Python wheel

You now find a Python wheel for SimpleITK in ./SimpleITK-build/Wrapping/Python/dist which you can install into your virtual environment

pip install --no-deps ./SimpleITK-build/Wrapping/Python/dist/SimpleITK-*arm64.whl

@giuseppefilitto
Copy link

@mlaves thanks man, I will try to do so and let you know!

@blowekamp blowekamp added this to the v2.1 milestone Apr 22, 2021
@giuseppefilitto
Copy link

@mlaves same issue here, I think that we could enjoy simpleITK on the apple silicon M1 when the next release will be out. I guess they added this issue to the v2.1 milestone

@dmtien
Copy link

dmtien commented Apr 29, 2021

@mlaves I get hung up on building the Python wheel on my M1. Everything seems good until the end:

[ 99%] Creating python virtual environment...
Traceback (most recent call last):
  File "setup.py", line 14, in <module>
    from SimpleITK._version import __version__
  File "/Users/tswk/SimpleITK-build/SimpleITK-build/Wrapping/Python/SimpleITK/__init__.py", line 18, in <module>
    from SimpleITK.SimpleITK import *
  File "/Users/tswk/SimpleITK-build/SimpleITK-build/Wrapping/Python/SimpleITK/SimpleITK.py", line 13, in <module>
    from . import _SimpleITK
ImportError: dlopen(/Users/tswk/SimpleITK-build/SimpleITK-build/Wrapping/Python/SimpleITK/_SimpleITK.so, 2): no suitable image found.  Did find:
	/Users/tswk/SimpleITK-build/SimpleITK-build/Wrapping/Python/SimpleITK/_SimpleITK.so: mach-o, but wrong architecture
	/Users/tswk/SimpleITK-build/SimpleITK-build/Wrapping/Python/SimpleITK/_SimpleITK.so: mach-o, but wrong architecture
make[3]: *** [Testing/Installation/pyvenv/bin/python] Error 1
make[3]: *** Deleting file `Testing/Installation/pyvenv/bin/python'
make[2]: *** [Wrapping/Python/CMakeFiles/PythonVirtualEnv.dir/all] Error 2
make[1]: *** [Wrapping/CMakeFiles/dist.dir/rule] Error 2
make: *** [dist] Error 2

@mlaves
Copy link
Author

mlaves commented Apr 29, 2021

@dmtien Is your terminal running in ARM mode?

@dmtien
Copy link

dmtien commented Apr 29, 2021

@mlaves Yes, I was running iterm2 which is a universal binary, but just to be safe, I repeated the steps in Apple's terminal with the same results. I have the same setup as you, except I'm running MacOS 11.3.

Does it have anything to do with the fact that you've invoked python 3.8 in the virtual environment, which isn't ARM64 native?

@mlaves
Copy link
Author

mlaves commented May 1, 2021

@dmtien I'm running python 3.8 from miniforge, which is ARM64 native. Maybe your python is still Intel?

@giuseppefilitto
Copy link

@dmtien if you follow exactly the guidelines of @mlaves you should have the same problems. Try to use the default terminal and after installing (miniforge 3 arm64 version) and homebrew (arm64 version as well) let us know!

@Alex97schmid
Copy link

I have the same issue like @dmtien.
@mlaves If it is possible to send us the compiled wheel, we should be able to install it via pip.

@blowekamp
Copy link
Member

Progress is being made with getting SimpleITK's Conda-forge package building for apple ARM. The libitk feedstock has been updated to build for, and now contains the package for osx-arm64.

@mlaves
Copy link
Author

mlaves commented May 21, 2021

@Alex97schmid Can you please ensure that your Python interpreter was compiled for arm64-osx? @dmtien never answered my question regarding this.

conda activate sitk
file `which python`

should return
/opt/homebrew/Caskroom/miniforge/base/envs/sitk/bin/python: Mach-O 64-bit executable arm64

Nevertheless, you'll find my wheel here: https://1drv.ms/u/s!AiF3lPpzI9TejrZFwFytnElPR2jAKA?e=uedfRs

@blowekamp Progress is great! libitk installs successfully for me on arm64-osx.

@Alex97schmid
Copy link

Thanks a lot for the wheel!, the installation worked! Currently I'm not using miniforge, I just created a virtual-environment with python 3.8, which I installed through homebrew. So far, I was quite successful installing the packages I need and they are all running natively. How is your experience with miniforge?

@mlaves
Copy link
Author

mlaves commented May 21, 2021

@Alex97schmid At the time I got my M1 Mac, miniforge seemed to be the only option to get native python and conda. My experience is quite good so far. Only had problems installing pandoc, which I use for LaTeX export of Jupyter notebooks. But I think this can be attributed to the missing ghc.

@MeteorsHub
Copy link

I met many undeclared identifier errors when building it using your approach:
error: use of undeclared identifier 'itk_fedisableexcept'

But I found that the wheel file you build is great on my mac. Could you please help to build a 1.2.4 version of SITK? Torchio needs Sitk under version 2.0

@blowekamp
Copy link
Member

But I found that the wheel file you build is great on my mac. Could you please help to build a 1.2.4 version of SITK? Torchio needs Sitk under version 2.0

Unfortunately, 1.2 is a quite an old version of SimpleIT and is based on ITK 4.x. ITK only began supporting apple ARM when the hardware was released with ITK version 5.2. I am unaware of any effort to back port the changes to ITK 4.x.

I believe it would be better use of the communities time to update torchio to support SimpleITK 2.x. It is better to move forward than backwards. Please let know if there is anything I can assist with that effort.

@zivy
Copy link
Member

zivy commented Jul 6, 2021

Hello @MeteorsHub,

There were issues with the threading model change in ITK/SimpleITK which affected Torchio, these were in SimpleITK versions 2.0.* (see here for details). These have been resolved in the upcoming release, 2.1.

For now you can use the latest SimpleITK pre-release wheel available from github. This line in Torchio's setup.py file will need to be changed to 'SimpleITK>=2.1.0'.

@MeteorsHub
Copy link

Hello @MeteorsHub,

There were issues with the threading model change in ITK/SimpleITK which affected Torchio, these were in SimpleITK versions 2.0.* (see here for details). These have been resolved in the upcoming release, 2.1.

For now you can use the latest SimpleITK pre-release wheel available from github. This line in Torchio's setup.py file will need to be changed to 'SimpleITK>=2.1.0'.

Thanks a lot. I've installed it. By the way, the SimpleITK should include macos-arm64 binary release.

@blowekamp
Copy link
Member

Apple ARM64 binary wheels have been uploaded to v2.1rc2 , please test and close the issue.

@blowekamp
Copy link
Member

SimpleITK v2.1.0 was released with Apple ARM64 support to pypi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants