libp2p / py-libp2p

The Python implementation of the libp2p networking stack 🐍 [under development]
https://libp2p.io
Other
481 stars 106 forks source link

Pip install error on MacOS - 'gmp.h' file not found #432

Closed ackhia closed 3 years ago

ackhia commented 3 years ago

What was wrong?

I get an error when I try a dev install with pip on MacOS 11.6

Code that produced the error

pip install -e ."[dev]"

Full error output

  Running setup.py clean for fastecdsa
Failed to build fastecdsa
Installing collected packages: fastecdsa, Faker, execnet, docopt, decorator, colorama, coincurve, click-default-group, bump2version, backcall, async-service, async-exit-stack, appnope, appdirs, twine, tox, towncrier, sphinx-rtd-theme, pytest-xdist, pytest-watch, pytest-trio, mypy-protobuf, mypy, libp2p, isort, ipython, flake8-bugbear, factory-boy, docformatter, bumpversion, black
    Running setup.py install for fastecdsa ... error
    ERROR: Command errored out with exit status 1:
     command: /Users/jon/projects/py-libp2p/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/sz/rn6yjd6928vdt0nll0ph6xb00000gn/T/pip-install-kbzzsd98/fastecdsa_232451070f0649ea993c13538898fbd3/setup.py'"'"'; __file__='"'"'/private/var/folders/sz/rn6yjd6928vdt0nll0ph6xb00000gn/T/pip-install-kbzzsd98/fastecdsa_232451070f0649ea993c13538898fbd3/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/sz/rn6yjd6928vdt0nll0ph6xb00000gn/T/pip-record-or__krsf/install-record.txt --single-version-externally-managed --compile --install-headers /Users/jon/projects/py-libp2p/venv/include/site/python3.10/fastecdsa
         cwd: /private/var/folders/sz/rn6yjd6928vdt0nll0ph6xb00000gn/T/pip-install-kbzzsd98/fastecdsa_232451070f0649ea993c13538898fbd3/
    Complete output (46 lines):
    running install
    /Users/jon/projects/py-libp2p/venv/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    running build
    running build_py
    creating build
    creating build/lib.macosx-11.6-arm64-3.10
    creating build/lib.macosx-11.6-arm64-3.10/fastecdsa
    copying fastecdsa/benchmark.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa
    copying fastecdsa/util.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa
    copying fastecdsa/__init__.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa
    copying fastecdsa/keys.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa
    copying fastecdsa/curve.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa
    copying fastecdsa/point.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa
    copying fastecdsa/ecdsa.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa
    creating build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/test_keygen.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/test_nonce_generation.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/test_signature_encoding.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/test_key_recovery.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/test_key_encoding.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/__init__.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/test_brainpool_ecdh.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/test_asn1.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/test_rfc6979_ecdsa.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/test_whitespace_parsing.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/test_prime_field_curve_math.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    copying fastecdsa/tests/test_p256_ecdsa.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/tests
    creating build/lib.macosx-11.6-arm64-3.10/fastecdsa/encoding
    copying fastecdsa/encoding/pem.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/encoding
    copying fastecdsa/encoding/util.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/encoding
    copying fastecdsa/encoding/__init__.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/encoding
    copying fastecdsa/encoding/sec1.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/encoding
    copying fastecdsa/encoding/der.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/encoding
    copying fastecdsa/encoding/asn1.py -> build/lib.macosx-11.6-arm64-3.10/fastecdsa/encoding
    running build_ext
    building 'fastecdsa.curvemath' extension
    creating build/temp.macosx-11.6-arm64-3.10
    creating build/temp.macosx-11.6-arm64-3.10/src
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -Isrc/ -I/Users/jon/projects/py-libp2p/venv/include -I/Users/jon/.pyenv/versions/3.10.0/include/python3.10 -c src/curve.c -o build/temp.macosx-11.6-arm64-3.10/src/curve.o -O2
    In file included from src/curve.c:1:
    src/curve.h:4:10: fatal error: 'gmp.h' file not found
    #include "gmp.h"
             ^~~~~~~
    1 error generated.
    error: command '/usr/bin/clang' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/jon/projects/py-libp2p/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/sz/rn6yjd6928vdt0nll0ph6xb00000gn/T/pip-install-kbzzsd98/fastecdsa_232451070f0649ea993c13538898fbd3/setup.py'"'"'; __file__='"'"'/private/var/folders/sz/rn6yjd6928vdt0nll0ph6xb00000gn/T/pip-install-kbzzsd98/fastecdsa_232451070f0649ea993c13538898fbd3/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/sz/rn6yjd6928vdt0nll0ph6xb00000gn/T/pip-record-or__krsf/install-record.txt --single-version-externally-managed --compile --install-headers /Users/jon/projects/py-libp2p/venv/include/site/python3.10/fastecdsa Check the logs for full command output.

Environment

I can't install eth_utils (same error) but I am using python 3.10.0 (via pyenv) on Mac OSX 11.6.

How can it be fixed?

Not sure. Maybe you need to install gmp and/or add pycrypto as a dependency. I tried manually installing both with no luck however.

ackhia commented 3 years ago

I resolved this issue with the following command. It seems like this problem is only present on Macs with an M1 chip.

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

I'll close this issue as this problem isn't directly related to this package.

tylerferrara commented 2 years ago

^ Can we add this to the README.md?

mhchia commented 2 years ago

I'm not sure which one is exactly you're referring to, but feel free to make a PR if you think it is legit.