Gevent cant be installed on M1 mac using poetry
Asked Answered
C

4

5

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.

Conglomerate answered 11/3, 2022 at 18:48 Comment(2)
The gevent version that you have installed is an x86 version and the install process that you are using is requesting arm. I don't know if there are arm versions of gevent, but likely it would be a newer version. Upgrade gevent if you can, or run under rosetta2.Steffie
Looks like you are mixing x86 and arm64 code, make sure to (re)install everything either x86 or arm64. Check your installed Python architecture as well.Yautia
C
7

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

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

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

Conglomerate answered 6/4, 2022 at 8:16 Comment(2)
Is there any way to run this without sudo?Azotic
Yes @Azotic , actually you shouldn't need to use sudo.also check your homebrew and poetry versionsTippet
T
3

You need to compile it from source. https://www.gevent.org/development/installing_from_source.html

arch -arm64 pip install --no-binary gevent gevent
Terrific answered 13/11, 2022 at 10:38 Comment(1)
Thanks, that's the only thing that worked.World
T
0

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.

Triste answered 13/3, 2022 at 8:33 Comment(2)
I updated pip to the last version and then I tried to install the latest gevent ersion but I got the same error.Tippet
Yep, as suggested by @Terrific building your own is the way.World
G
0

I had to install it on my pc (not in virtual env). Then installing inside the virtual env worked.

So on Apple M1, run

sudo arch -arm64 pip3 install --no-binary gevent gevent

and then create and activate your python virtual env,

python3 -m venv env
source env/bin/activate
pip install -U pip
pip install gevent

You are done if you see the output like:

Collecting gevent
  Using cached gevent-22.10.2.tar.gz (6.6 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Collecting zope.event
  Downloading zope.event-4.6-py2.py3-none-any.whl (6.8 kB)
Collecting greenlet>=2.0.0
  Using cached greenlet-2.0.2.tar.gz (164 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: setuptools in ./env/lib/python3.9/site-packages (from gevent) (58.0.4)
Collecting zope.interface
  Downloading zope.interface-6.0-cp39-cp39-macosx_11_0_arm64.whl (202 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 202.4/202.4 kB 2.9 MB/s eta 0:00:00
Building wheels for collected packages: gevent
  Building wheel for gevent (pyproject.toml) ... done
  Created wheel for gevent: filename=gevent-22.10.2-cp39-cp39-macosx_10_9_universal2.whl size=2908594 sha256=c7184d20566f559ddec3b60250fbf9b8ffda973c14c93f70fc8ae22aa7b85521
  Stored in directory: /Users/pavankrn/Library/Caches/pip/wheels/7f/f7/e0/8b48eb5aabb2beca135a3fdde34df3b6938cfccf4def985a45
Successfully built gevent
Installing collected packages: zope.interface, zope.event, greenlet, gevent
  DEPRECATION: greenlet is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for greenlet ... done

If you freeze your requirements pip freeze > requirements.txt you will find the following packages.

gevent==22.10.2
greenlet==2.0.2
zope.event==4.6
zope.interface==6.0
Grigri answered 20/3, 2023 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.