'Gevent cant be installed on M1 mac using poetry

I tried to install many dependencies for a virtual environment using poetry. When it gets to gevent (20.9.0) it gets the following

import error:

ImportError: dlopen(/private/var/folders/21/wxg5bdsj1w3f3j_9sl_pktbw0000gn/T/pip-build-env-50mwte36/overlay/lib/python3.8/site-packages/_cffi_backend.cpython-38-darwin.so,
0x0002): tried:
'/private/var/folders/21/wxg5bdsj1w3f3j_9sl_pktbw0000gn/T/pip-build-env-50mwte36/overlay/lib/python3.8/site-packages/_cffi_backend.cpython-38-darwin.so'
(mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_cffi_backend.cpython-38-darwin.so' (no such file), '/usr/lib/_cffi_backend.cpython-38-darwin.so' (no such file)

I've tried to use pip3 instead, but still had the same problem.



Solution 1:[1]

I've have this problem with other libraries also and this solution worked some times:

sudo arch -arm64 <poetry or pip> install <lib to istall>

Using arch -arm64 allowed me to install the rigt wheel for the M1 processor

Solution 2:[2]

The M1 needs either all x86 code or all arm64 code in a process. This issue is caused by a program attempting to load an x86_64-only library from a native arm64 process. This unfortunately can't be done (See here).

With specific regard to gevent, the project page here includes the following information:

Beginning with gevent 20.12.0, 64-bit ARM binaries are distributed on PyPI for aarch64 manylinux2014 compatible systems. Installing these needs a very recent version of pip. These wheels do not contain the c-ares resolver, are not tested, and are built with very low levels of optimizations. Serious production users of gevent on 64-bit ARM systems are encouraged to build their own binary wheels.

I'm not sure if arm64 is exclusively supported on Linux, but in any case, I would suggest updating your versions of both gevent and pip to the lastest possible versions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sergio García
Solution 2 beeselmane