fastobo / fastobo-py

Faultless AST for Open Biomedical Ontologies in Python.
http://fastobo.readthedocs.io
MIT License
24 stars 4 forks source link

ImportError on Mac M1 architecture #302

Closed matthiaskoenig closed 1 year ago

matthiaskoenig commented 2 years ago

Trying fastobo in the Mac M1 results in the following errors:

Python 3.10.4 (main, Apr 26 2022, 19:36:29) [Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import fastobo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/utkarshchaurasia/Documents/Projects/venvpy/lib/python3.10/site-packages/fastobo.cpython-310-darwin.so, 0x0002): tried: '/Users/utkarshchaurasia/Documents/Projects/venvpy/lib/python3.10/site-packages/fastobo.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/fastobo.cpython-310-darwin.so' (no such file), '/usr/lib/fastobo.cpython-310-darwin.so' (no such file)

@UtkarshChaurasia Have a look.

althonos commented 2 years ago

Hi @matthiaskoenig , did you compile the package yourself or install from a wheel from PyPI? This looks to me like a usual error caused by Rosetta, where the extension gets compiled for the wrong target, or installed in the wrong place...

matthiaskoenig commented 2 years ago

@UtkarshChaurasia had the issue (please provide more information asap). Unfortunately I don't have access to a M1 myself.

As I understand things it was installed via pip (i.e. wheel) and not compiled. Normally other libraries check if a version exists for the architecture. How could I force a compile installation? Would a checkout of the source code with a pip install of the local source work (sorry not an expert in wheels/installation)?

To manually compile would be a workaround for now so that @UtkarshCharausia can work on the code. In the end we would require a pip package from pypi which works because we run a lot of CI testing in tox with different python versions.

althonos commented 2 years ago

I don't have an M1 myself either, so these kinds of issues are always hard to figure out. For now, you can try installing from PyPI with the source version using:

pip install --no-binary=fastobo fastobo

Otherwise, maybe try running Python with the arch tool so that it's running in Aarch64 mode both when installing and using the library:

arch -arm64 pip install fastobo
arch -arm64 python -c 'import fastobo'
ravwojdyla commented 1 year ago

👋 we have run into this issue as well. Also on Apple silicon laptop.

To reproduce pip log:

> # create clean python env:
> conda create -n test-py310 'python=3.10'
> pip install fastobo
Collecting fastobo
  Using cached fastobo-0.12.1-cp310-cp310-macosx_10_15_universal2.whl (1.8 MB)
Installing collected packages: fastobo
Successfully installed fastobo-0.12.1
>>> import fastobo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(<REDACTED>/lib/python3.10/site-packages/fastobo.cpython-310-darwin.so, 0x0002): tried: '<REDACTED>/lib/python3.10/site-packages/fastobo.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '<REDACTED>/lib/python3.10/site-packages/fastobo.cpython-310-darwin.so' (no such file), '/<REDACTED>/lib/python3.10/site-packages/fastobo.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

So this is installed:

fastobo-0.12.1-cp310-cp310-macosx_10_15_universal2.whl (1.8 MB view hashes)

The architecture is universal2, so one would expect that it supports both x86_64 and arm64. But there might be an issue with the build or that particular release:

> file <REDACTED>/lib/python3.10/site-packages/fastobo.cpython-310-darwin.so
<REDACTED>/lib/python3.10/site-packages/fastobo.cpython-310-darwin.so: Mach-O 64-bit dynamically linked shared library x86_64

There's only a single architecture: x86_64 and thus an error. I believe universal2 is not the right architecture, as it stands right now there are probably two options:

ravwojdyla commented 1 year ago

And this is what you can find inside the fastobo-0.12.1-cp310-cp310-macosx_10_15_universal2.whl :

> find .
./fastobo-0.12.1.dist-info
./fastobo-0.12.1.dist-info/RECORD
./fastobo-0.12.1.dist-info/WHEEL
./fastobo-0.12.1.dist-info/COPYING
./fastobo-0.12.1.dist-info/top_level.txt
./fastobo-0.12.1.dist-info/METADATA
./fastobo.cpython-310-darwin.so

> file ./fastobo.cpython-310-darwin.so
./fastobo.cpython-310-darwin.so: Mach-O 64-bit dynamically linked shared library x86_64
althonos commented 1 year ago

This is a change that appeared after Python binaries for MacOS started being built in universal2 mode, the platform flags creeped into the wheel generation while Rust was only building wheels for x86-64. I'll make a new release with the proper flags, and change wheel generation to use cibuildwheel so that I can hopefully provide wheels for both x86 and aarch64 MacOS.

ravwojdyla commented 1 year ago

@althonos thanks! looking forward to the fixed arm64 release 🤞

althonos commented 1 year ago

@ravwojdyla : I updated the CI/CD today so there are now aarch64 wheels for MacOS for a pre-released, would you mind trying them (pip install -U fastobo --pre)? If they work, I'll make a proper release.

ravwojdyla commented 1 year ago

@althonos works now - thank you!

althonos commented 1 year ago

Nice! I'll make a proper v0.12.2 and yank v0.12.1 to prevent future issues.

matthiaskoenig commented 1 year ago

Thanks for the bugfix.