Synss / python-mbedtls

Cryptographic library with an mbed TLS back end
MIT License
79 stars 28 forks source link

Installation failed on MacOS with Python 3.7 #26

Closed Alan-Lynn closed 4 years ago

Alan-Lynn commented 4 years ago

I don't know if it only happened on my side. The system information is as below:

MacOS 10.14.6
Python 3.7.3
pip 19.1.1

When installing the package with command "pip install python-mbedtls -i https://pypi.python.org/simple", I got the following error:

 ......
 build-3.7.3/temp.macosx-10.7-x86_64-3.7/pyrex/mbedtls/_platform.c:596:10: fatal error: 'mbedtls/platform_util.h' file not found
  #include "mbedtls/platform_util.h"
           ^~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for python-mbedtls

The full logs can be found in attached logs.txt Please have a look at it. Thanks.

Synss commented 4 years ago

Hi Alan-Lynn,

You are not doing anything wrong. That reminds me that I should complete the documentation.

I distribute binary wheels for Linux only. I guess I could make some for MacOS as well. Anyway, you must first install libmbedtls (the C library) before you can compile python-mbedtls. If you use MacPorts, you can get libmbedtls with port install mbedtls. They distribute a fairly recent version so that is fine. Homebrew has it as well. If you do not use a package manager, libmbedtls is easy to build from source, check it out and

# from mbedtls top-level directory
mkdir build
cd build
CFLAGS="-DMBEDTLS_ARIA_C=ON" \
SHARED="ON" \
make -C .. -j lib
sudo make -C .. -j install

or with CMake

# from mbedtls top-level directory
mkdir build
cd build
CFLAGS="-DMBEDTLS_ARIA_C=ON" \
cmake .. \
    -DENABLE_TESTING=OFF \
    -DUSE_SHARED_MBEDTLS_LIBRARY=ON \
    -DUSE_STATIC_MBEDTLS_LIBRARY=OFF
make -j
sudo make -j install

should install mbedtls. Then you can pip install python-mbedtls.

I develop on MacOS so I know that it works there as well.

jayvdb commented 4 years ago

This also happens on Leap 15.1 . The problem is the old version of libmbedtls 2.8.0.

https://build.opensuse.org/package/live_build_log/home:jayvdb:strictyaml/python-python-mbedtls/openSUSE_Leap_15.1/x86_64

....
[   46s] building 'mbedtls._ringbuf' extension
[   46s] creating build-2.7.14/temp.linux-x86_64-2.7/build-2.7.14
[   46s] creating build-2.7.14/temp.linux-x86_64-2.7/build-2.7.14/temp.linux-x86_64-2.7
[   46s] creating build-2.7.14/temp.linux-x86_64-2.7/build-2.7.14/temp.linux-x86_64-2.7/pyrex
[   46s] creating build-2.7.14/temp.linux-x86_64-2.7/build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls
[   46s] gcc -pthread -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -DOPENSSL_LOAD_CONF -fwrapv -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -fPIC -I/usr/include/python2.7 -c build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c -o build-2.7.14/temp.linux-x86_64-2.7/build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.o
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c: In function '__Pyx_PyInt_EqObjC':
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:20232:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s]          Py_RETURN_TRUE;
[   46s]          ^~~~~~~~~~~~~~
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:20238:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s]          if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
[   46s]          ^~
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:20238:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:20248:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s]              if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
[   46s]              ^~
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:20248:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:20251:17: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s]                  Py_RETURN_FALSE;
[   46s]                  ^~~~~~~~~~~~~~~
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:20256:17: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s]                  Py_RETURN_FALSE;
[   46s]                  ^~~~~~~~~~~~~~~
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:20284:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s]          if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
[   46s]          ^~
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:20284:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:20290:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s]          if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
[   46s]          ^~
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:20290:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c: In function '__Pyx_PyBool_FromLong':
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:23866:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   46s]    return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
[   46s]    ^~~~~~
[   46s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.c:23866:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   50s] gcc -pthread -shared -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g build-2.7.14/temp.linux-x86_64-2.7/build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_ringbuf.o -L -L -L/usr/lib64 -lmbedcrypto -lmbedtls -lmbedx509 -lpython2.7 -o build-2.7.14/lib.linux-x86_64-2.7/mbedtls/_ringbuf.so
[   50s] cythoning src/mbedtls/version.pyx to build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/version.c
[   51s] building 'mbedtls.version' extension
[   51s] gcc -pthread -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -DOPENSSL_LOAD_CONF -fwrapv -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -fPIC -I/usr/include/python2.7 -c build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/version.c -o build-2.7.14/temp.linux-x86_64-2.7/build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/version.o
[   51s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/version.c: In function '__pyx_pf_7mbedtls_7version_has_feature':
[   51s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/version.c:1948:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   51s]      __Pyx_INCREF(Py_False);
[   51s]      ^~~~~~~~~~~~
[   51s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/version.c: In function '__Pyx_PyBool_FromLong':
[   51s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/version.c:4335:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   51s]    return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
[   51s]    ^~~~~~
[   51s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/version.c:4335:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[   51s] gcc -pthread -shared -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g build-2.7.14/temp.linux-x86_64-2.7/build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/version.o -L -L -L/usr/lib64 -lmbedcrypto -lmbedtls -lmbedx509 -lpython2.7 -o build-2.7.14/lib.linux-x86_64-2.7/mbedtls/version.so
[   51s] cythoning src/mbedtls/_random.pyx to build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_random.c
[   52s] warning: src/mbedtls/_random.pyx:156:0: Overriding cdef method with def method.
[   53s] building 'mbedtls._random' extension
[   53s] gcc -pthread -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -DOPENSSL_LOAD_CONF -fwrapv -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -fPIC -I/usr/include/python2.7 -c build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_random.c -o build-2.7.14/temp.linux-x86_64-2.7/build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_random.o
[   53s] build-2.7.14/temp.linux-x86_64-2.7/pyrex/mbedtls/_random.c:600:10: fatal error: mbedtls/platform_util.h: No such file or directory
[   53s]  #include "mbedtls/platform_util.h"
[   53s]           ^~~~~~~~~~~~~~~~~~~~~~~~~
[   53s] compilation terminated.
[   53s] error: command 'gcc' failed with exit status 1

i.e. https://github.com/Synss/python-mbedtls/blob/master/src/mbedtls/_platform.pxd is where this is assumed to exist.

Synss commented 4 years ago

Ah! I did not think about that. Anyway, I am not sure that I want to support any old version of mbedtls. I would rather try to print a more helpful error message if the version of mbedtls is too old.

Alan-Lynn commented 4 years ago

Hi Synss, Many thanks for so detailed explanation. And it solved the problem. I use home-brew. So I just "brew install mbedtls" first, and then "pip install python-mbedtls". Everything works fine. Thanks. :)

Synss commented 4 years ago

There now is a more helpful message on Linux and MacOS if mbedtls is either missing or too old to work. Thank you for your feedback.