python-jose/pycrypto installation failing on Windows 10

Published on 08 December 2017

In a recent Django project I was working on, I decided to use Auth0 as identity provider. I followed the Auth0 official documentation to get the things in place. It needs the user to install python-jose Python module. python-jose is used to handle JWT tokens. It is one of the most feature complete Python library for the purpose along with jwcrypto.

A normal installation using pip is the way to go. However, when I tried installing this package, it failed. I am using Python 3.6 on Windows 10. Looking into the command line output, it was an error with compilation of pycryto module. This module is compiled on the user's system and need Visual C++ installation corresponding to the Python version. Based on the logs, it was working with VC which came with Visual Studio 2015.

Exact error is reproduced below. Non-error parts of log are omitted.

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc/ -Isrc/inc-msvc/ -Ic:\workarea\santosh\medicineman\src\medicineman\medicineman\medicineman\env\include "-IC:\Program Files\Python36\include" "-IC:\Program Files\Python36\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\winrt" /Tcsrc/winrand.c /Fobuild\temp.win-amd64-3.6\Release\src/winrand.obj
    winrand.c
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(26): error C2061: syntax error: identifier 'intmax_t'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(27): error C2061: syntax error: identifier 'rem'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(27): error C2059: syntax error: ';'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(28): error C2059: syntax error: '}'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(30): error C2061: syntax error: identifier 'imaxdiv_t'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(30): error C2059: syntax error: ';'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(40): error C2143: syntax error: missing '{' before '__cdecl'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(41): error C2146: syntax error: missing ')' before identifier '_Number'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(41): error C2061: syntax error: identifier '_Number'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(41): error C2059: syntax error: ';'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(42): error C2059: syntax error: ')'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(45): error C2143: syntax error: missing '{' before '__cdecl'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(46): error C2146: syntax error: missing ')' before identifier '_Numerator'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(46): error C2061: syntax error: identifier '_Numerator'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(46): error C2059: syntax error: ';'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(46): error C2059: syntax error: ','
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(48): error C2059: syntax error: ')'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(50): error C2143: syntax error: missing '{' before '__cdecl'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(56): error C2143: syntax error: missing '{' before '__cdecl'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(63): error C2143: syntax error: missing '{' before '__cdecl'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(69): error C2143: syntax error: missing '{' before '__cdecl'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(76): error C2143: syntax error: missing '{' before '__cdecl'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(82): error C2143: syntax error: missing '{' before '__cdecl'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(89): error C2143: syntax error: missing '{' before '__cdecl'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt\inttypes.h(95): error C2143: syntax error: missing '{' before '__cdecl'
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

The cause for the issue is the first line here. Others might be the downstream errors arising from the first one. Googling a bit for the solution lead me to some of the following solutions:

  1. Use pycryptodome as pycrpto is out of date. It was not a choice for me as it was a dependency of another package.
  2. Install using precompiled binary packages. I was not able to find one for my version of Python and thus it was out of choice for me.
  3. Next remaining option was to get the compilation successful in my system. I decided to invest time on this.

A bit of further googling led me to the root of problem. As described in this Stack Overflow post, the problem was arising from #include <stdint.h> missing from include/pyport.h file. This causes intmax_t to be reported undefined. As a workaround, we need to force VC compiler to include this file using OS environment variable CL. The exact steps are:

  • Open developer console for your version of Visual Studio with Administrator privilege. Or Open command prompt as Admin and source vsvars32.bat file for your version of Visual Studio.
  • Set the environment variable using CL=-FI"%VCINSTALLDIR%\INCLUDE\stdint.h" in the command prompt.
  • Now install pycrypto (or python-jose) with pip install pycrypto.

The installation should be successful now. Let me know in the comments if you are facing any other issue.

comments powered by Disqus