AntonKueltz / fastecdsa

Python library for fast elliptic curve crypto
https://pypi.python.org/pypi/fastecdsa
The Unlicense
264 stars 77 forks source link

Having difficulty on Python 3.5.2, macOS Sierra. #4

Closed amcgregor closed 7 years ago

amcgregor commented 7 years ago

Howdy!

I'm having some trouble installing fastecdsa on Python 3.5.2, installed via the official packages, with homebrew-supplied libgmp.

In a fresh virtual environment, pip install fastecdsa explodes gloriously:

Collecting fastecdsa
  Using cached fastecdsa-1.1.3.tar.gz
Installing collected packages: fastecdsa
  Running setup.py install for fastecdsa ... error
    Complete output from command /Users/amcgregor/Projects/test/.venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/xp/zg8pvtm16tl_tx4fp4sthm7c0000gn/T/pip-build-1nokhsj2/fastecdsa/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/xp/zg8pvtm16tl_tx4fp4sthm7c0000gn/T/pip-ahgmwxsn-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/amcgregor/Projects/test/.venv/include/site/python3.5/fastecdsa:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.6-intel-3.5
    creating build/lib.macosx-10.6-intel-3.5/fastecdsa
    copying fastecdsa/__init__.py -> build/lib.macosx-10.6-intel-3.5/fastecdsa
    copying fastecdsa/curve.py -> build/lib.macosx-10.6-intel-3.5/fastecdsa
    copying fastecdsa/ecdsa.py -> build/lib.macosx-10.6-intel-3.5/fastecdsa
    copying fastecdsa/keys.py -> build/lib.macosx-10.6-intel-3.5/fastecdsa
    copying fastecdsa/test.py -> build/lib.macosx-10.6-intel-3.5/fastecdsa
    copying fastecdsa/util.py -> build/lib.macosx-10.6-intel-3.5/fastecdsa
    running build_ext
    building 'fastecdsa.curvemath' extension
    creating build/temp.macosx-10.6-intel-3.5
    creating build/temp.macosx-10.6-intel-3.5/src
    /usr/bin/clang -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -Isrc/ -I/Users/amcgregor/Projects/test/.venv/include -I/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -c src/curveMath.c -o build/temp.macosx-10.6-intel-3.5/src/curveMath.o -O2
    In file included from src/curveMath.c:1:
    src/curveMath.h:10:10: fatal error: 'gmp.h' file not found
    #include <gmp.h>
             ^
    1 error generated.
    error: command '/usr/bin/clang' failed with exit status 1

    ----------------------------------------
Command "/Users/amcgregor/Projects/test/.venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/xp/zg8pvtm16tl_tx4fp4sthm7c0000gn/T/pip-build-1nokhsj2/fastecdsa/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/xp/zg8pvtm16tl_tx4fp4sthm7c0000gn/T/pip-ahgmwxsn-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/amcgregor/Projects/test/.venv/include/site/python3.5/fastecdsa" failed with error code 1 in /private/var/folders/xp/zg8pvtm16tl_tx4fp4sthm7c0000gn/T/pip-build-1nokhsj2/fastecdsa/

With --global-option=build_ext --global-option="-I/usr/local/include" --global-option="-L/usr/local/lib" in there, we get further:

/Users/amcgregor/Projects/test/.venv/lib/python3.5/site-packages/pip/commands/install.py:180: UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.
  cmdoptions.check_install_build_global(options)
Collecting fastecdsa
  Using cached fastecdsa-1.1.3.tar.gz
Installing collected packages: fastecdsa
  Running setup.py install for fastecdsa ... done
Successfully installed fastecdsa-1.1.3
pip install --global-option=build_ext --global-option="-I/usr/local/include"   1.60s user 0.67s system 91% cpu 2.480 total

However, when running python -c "from fastecdsa import curve, ecdsa, keys":

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/amcgregor/Projects/test/.venv/lib/python3.5/site-packages/fastecdsa/curve.py", line 1, in <module>
    from fastecdsa import curvemath
ImportError: dlopen(/Users/amcgregor/Projects/test/.venv/lib/python3.5/site-packages/fastecdsa/curvemath.cpython-35m-darwin.so, 2): Symbol not found: _Py_InitModule4_64
  Referenced from: /Users/amcgregor/Projects/test/.venv/lib/python3.5/site-packages/fastecdsa/curvemath.cpython-35m-darwin.so
  Expected in: flat namespace
 in /Users/amcgregor/Projects/test/.venv/lib/python3.5/site-packages/fastecdsa/curvemath.cpython-35m-darwin.so

What might be going on here?

AntonKueltz commented 7 years ago

Hi there, a couple things I can think of off the top of my head. First is that I haven't written the C extension modules to work with Python3 so there might well be issues using the module with v3.5.2 (it does work against all versions of Python2 I've tested). I think the installation issue may be in regard to where clang looks for header files, I'll have to look at that a little further. I do plan to make this package Python3 compatible but at the moment the only version that is stable / tested is on Python2, sorry about that.

amcgregor commented 7 years ago

No worries, I was suspecting it was something like that. For when you do get to Python 3 compatibility, I'd highly, highly recommend using the cffi package, as it's extremely portable across runtimes.

AntonKueltz commented 7 years ago

I just pushed some changes for python3 compatibility, I tested them in a virtualenv using python3.4 and they cleared the test suite. Haven't benchmarked performance but I see no reason it would be much different from the python2 performance. Let me know if you're still having trouble ($ pip install fastecdsa==1.2.1 should do the trick).

amcgregor commented 7 years ago

Great success! Thank you for the extremely prompt turnaround on this!

Tested on Python 3.5.2 in a venv on macOS Sierra via:

# This is more robust than the uglier version passed to PIP.
export LDFLAGS="-L$(brew --prefix gmp)/lib" CFLAGS="-I$(brew --prefix gmp)/include"
pip install 'fastecdsa==1.2.1'
python -c "from fastecdsa import curve, ecdsa, keys"

The exception that was raised is no longer. Thanks again!

AntonKueltz commented 7 years ago

Happy to hear that did the trick for you! :)

[for historical reference issue fixed in 3c2162c]