-
-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Issue
I've been doing some development with nimpy & nimporter on an M1 Max (ARM64) and have had quite a few obstacles. Currently, I'm using nimporter to compile on demand in an amd64 Docker container to ensure everything works.
If I tried to precompile the nim files using nimporter build/compile I would run into an error when running the Docker container as the binaries were built for arm64, but the container is amd64, which looks like this:
Traceback (most recent call last):
File "main.py", line 7, in <module>
import nimporter, nim_math
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 971, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 914, in _find_spec
File "/usr/local/lib/python3.8/site-packages/nimporter.py", line 1300, in find_spec
return Nimporter.import_nim_code(fullname, path, library=True)
File "/usr/local/lib/python3.8/site-packages/nimporter.py", line 957, in import_nim_code
cls.__validate_spec(spec)
File "/usr/local/lib/python3.8/site-packages/nimporter.py", line 1025, in __validate_spec
raise NimporterException(error_message) from import_error
nimporter.NimporterException: Error importing /nim_math/__pycache__/nim_math.so
Error Message:
/nim_math/__pycache__/nim_math.so: invalid ELF header
Which I have assumed from testing is because the platforms do not match.
Fix
My suggestion is to add a --cpu flag onto the build & compile command, mimicking the flag from the nim compile command found here
This issue isn't pressing as it is still possible to run nimporter and numpy, however, runtime compilation tends to be quite slow.
If you would like, I would be able to add this functionality and create a PR to implement it.
For other context, I've been building exclusively in a Docker container for testing purposes and due to arm64 installation issues with nim (I will be attempting to solve these as I go and will provide any updates here for anyone that is struggling with a similar issue)