ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
608 stars 161 forks source link

`pip install antspyx` installs arm-compiled ANTsPy on intel-based mac (py=3.9) #524

Closed dipterix closed 5 months ago

dipterix commented 6 months ago
pip install antspyx
python
>>> import ants
ImportError: ... addNoiseToImage.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64' but ...)

Not working setups:

Python version: 3.9 ANTsPyx version: 0.4.2, 0.3.8 OSX version: 13.4, Intel CPU

Working setups:

Python version: 3.8 ANTsPyx version: 0.4.2, 0.3.8 OSX version: 13.4, Intel CPU

cookpa commented 6 months ago

Cannot reproduce with an Intel Mac running OS 12.7. I wonder if it's a problem with pip detecting the right package to install, or maybe it's an issue with Mac OS 13 vs 12.

% python             
Python 3.9.18 (main, Sep 11 2023, 08:38:23) 
[Clang 14.0.6 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ants
>>> img = ants.image_read( ants.get_ants_data('r16') )
>>> print(img)
ANTsImage
     Pixel Type : float (float32)
     Components : 1
     Dimensions : (256, 256)
     Spacing    : (1.0, 1.0)
     Origin     : (0.0, 0.0)
     Direction  : [1. 0. 0. 1.]

>>> 

Can you paste the output of pip install antspyx? Might be some clues there

dipterix commented 6 months ago

I built a reproducible github action here https://github.com/dipterix/ravemanager/actions/runs/7630738677/job/20787088190#step:7:1466

+ '/Users/runner/Library/r-rpymat/miniconda/envs/rpymat-conda-env/bin/python' -m pip install --upgrade --no-user antspynet
Collecting antspynet
  Downloading antspynet-0.2.3-py3-none-any.whl.metadata (8.6 kB)
Collecting antspyx (from antspynet)
  Downloading antspyx-0.4.2-cp39-cp39-macosx_12_0_universal2.whl.metadata (781 bytes)
...
  ImportError: dlopen(/Users/runner/Library/r-rpymat/miniconda/envs/rpymat-conda-env/lib/python3.9/site-packages/ants/lib/addNoiseToImage.cpython-39-darwin.so, 0x0002): tried: '/Users/runner/Library/r-rpymat/miniconda/envs/rpymat-conda-env/lib/python3.9/site-packages/ants/lib/addNoiseToImage.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have (arm64), need (x86_64h)))

The runner itself is running under intel chip, and the enclosing conda, including pip are built under conda-forge/osx-64

cookpa commented 6 months ago

Thanks, I tried installing antspynet, rather than antspyx directly, as in the runner. For me, it installs correctly (I'm running Monterey, 12.7)

% conda activate antspynettest_nocache
(antspynettest_nocache) pcook@athena NOT_BACKED_UP % pip install --no-cache-dir antspynet
Collecting antspynet
  Downloading antspynet-0.2.3-py3-none-any.whl.metadata (8.6 kB)
Collecting antspyx (from antspynet)
  Downloading antspyx-0.4.2-cp39-cp39-macosx_10_9_x86_64.whl.metadata (781 bytes)

From your runner output,

Collecting antspynet
  Downloading antspynet-0.2.3-py3-none-any.whl.metadata (8.6 kB)
Collecting antspyx (from antspynet)
  Downloading antspyx-0.4.2-cp39-cp39-macosx_12_0_universal2.whl.metadata (781 bytes)
Collecting keras (from antspynet)

It pulls from antspyx-0.4.2-cp39-cp39-macosx_12_0_universal2.whl.metadata. I'll take a look at that wheel next

cookpa commented 6 months ago
pip install --no-cache-dir antspyx-0.4.2-cp39-cp39-macosx_12_0_universal2.whl 
ERROR: antspyx-0.4.2-cp39-cp39-macosx_12_0_universal2.whl is not a supported wheel on this platform.

I can't even install the wheel, it says right away it's not compatible. Not sure what's happening with the runner.

cookpa commented 6 months ago

Pinging pypi maintainers @stnava @ravnoor @ntustison

It looks like the universal wheel

https://files.pythonhosted.org/packages/fb/10/fd8a11f410edccbaf2d62b70a008aefe2b7ae79dbd2366d7a479a8b7076f/antspyx-0.4.2-cp39-cp39-macosx_12_0_universal2.whl

only provides arm64 binaries. It's causing an Intel Github runner to fail to install (as above), though on my Intel mac machine pip selects a different wheel, which works.

dipterix commented 6 months ago

I removed antspynet from installation and the problem still exists: https://github.com/dipterix/ravemanager/actions/runs/7635397131/job/20800760019#step:7:1848

ravnoor commented 6 months ago

I setup a minimal conda environment with the results identical to @cookpa's testing. Probably the universal wheel in question is corrupted or wasn't built/tested properly. It's the only universal binary on PyPi so it's hard to determine if this was a systemic or a one-off issue.

The easiest fix would be to delete the universal binary from PyPi, since it's made redundant by more recently built/tested cp39-macosx_10_9_x86_64 and cp39-macosx_11_0_arm64 wheels.

ravnoor commented 6 months ago

ANTsX/ANTsPy#527 should make scenarios such as this less likely.

cookpa commented 6 months ago

I'm good with deleting, is that OK @stnava ? Specifically, removing antspyx-0.4.2-cp39-cp39-macosx_12_0_universal2.whl (f62c8751d817d5c458d2867f36fec58442907dda7a95ae112c38f6c953121ce9)

stnava commented 6 months ago

sure whatever works

cookpa commented 6 months ago

@stnava @ntustison could I please be added as an antspyx PyPI maintainer?

stnava commented 6 months ago

what is your pypi user name?

cookpa commented 6 months ago

Sorry cookpa over there too

cookpa commented 6 months ago

Thanks @stnava - looks like deletions are only available to "owners", would you be able to remove antspyx-0.4.2-cp39-cp39-macosx_12_0_universal2.whl? I think that should solve this issue.

Thanks

stnava commented 6 months ago

done

cookpa commented 6 months ago

Thanks! @dipterix hopefully you can install on x86 now

dipterix commented 6 months ago

Great! Do I need to compile on the fly? (Btw I just realized we are at the same building!

cookpa commented 6 months ago

I think it should get a pre-compiled binary, on my Intel Mac it gets antspyx-0.4.2-cp39-cp39-macosx_10_9_x86_64.whl.