fastecdsa: Cannot install in macOS BigSur (M1 chip)

I’m trying to install fastecdsa on macOS BigSur (M1 chip) by running

(venv) $ pip3 install fastecdsa

and even though I previously installed gmp:

$ brew install gmp

it cant find the lib, no matter what I do

    src/curve.h:4:10: fatal error: 'gmp.h' file not found
    #include "gmp.h"

Although the error changed when I created a symlink

ln -s /opt/homebrew/include/gmp.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include

and now I get:

    ld: library not found for -lgmp
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command '/usr/bin/gcc' failed with exit code 1

I also tried:

  • passing the path via env CFLAGS, LDFLAGS and both via global env export (export CFLAGS=...)
LDFLAGS=-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib pip3 install fastecdsa
CFLAGS=-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include pip3 install fastecdsa
  • xcode-select --install
  • endlessly brew uninstall gmp and brew install gmp, even brew reinstall gmp and brew unlink gmp
  • installing rosetta2
  • turning it off and on again

I can’t put my finger on it 😦

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 21 (3 by maintainers)

Most upvoted comments

This worked for me:

CFLAGS=-I/opt/homebrew/opt/gmp/include LDFLAGS=-L/opt/homebrew/opt/gmp/lib pip install fastecdsa

Thanks. I did a bit of everything proposed here by using arm64, compiler flags, etc:

arch -arm64 brew install gmp

CFLAGS=-I/opt/homebrew/opt/gmp/include LDFLAGS=-L/opt/homebrew/opt/gmp/lib python3 -m pip install --no-binary :all: --no-use-pep517 fastecdsa

And although installation succeeded, execution fails:

  File "/Users/martriay/dev/openzeppelin/cairo-contracts/env/lib/python3.9/site-packages/fastecdsa/point.py", line 1, in <module>
    from fastecdsa import curvemath
ImportError: dlopen(/Users/martriay/dev/openzeppelin/cairo-contracts/env/lib/python3.9/site-packages/fastecdsa/curvemath.cpython-39-darwin.so, 2): Symbol not found: ___gmpz_add
  Referenced from: /Users/martriay/dev/openzeppelin/cairo-contracts/env/lib/python3.9/site-packages/fastecdsa/curvemath.cpython-39-darwin.so
  Expected in: flat namespace
 in /Users/martriay/dev/openzeppelin/cairo-contracts/env/lib/python3.9/site-packages/fastecdsa/curvemath.cpython-39-darwin.so

This worked for me:

CFLAGS=-I/opt/homebrew/opt/gmp/include LDFLAGS=-L/opt/homebrew/opt/gmp/lib pip install fastecdsa

This didn’t work for me on an Intel chip. Instead I had to change the path of gmp to where it actually is (ie where homebrew installs it)

CFLAGS=-I/usr/local/Cellar/gmp/6.2.1_1/include LDFLAGS=-L/usr/local/Cellar/gmp/6.2.1_1/lib pip install fastecdsa

hey guys, i had this exact same problem on mac monterey m1 the way i solved it:

  1. uninstalled python completely
  2. installed python3.x exactly like as this article says: https://diewland.medium.com/how-to-install-python-3-7-on-macbook-m1-87c5b0fcb3b5
  3. ibrew install gmp
  4. then it should work 😃

@martriay

This worked for me:

CFLAGS=-I/opt/homebrew/opt/gmp/include LDFLAGS=-L/opt/homebrew/opt/gmp/lib pip install fastecdsa

This also worked for me, thank you @milancermak! I’m on macOS big sur 11.2.3

was able to make this work on M1, by

  1. ibrew install gmp as suggested by @neilmi
  2. python3 -m pip install --no-binary :all: fastecdsa as suggested by @justinba1010

This worked Dude, thanks for that