40

pip install pycrypto works fine with python3.5.2 but fails with python3.6 with the following error:

inttypes.h(26): error C2061: syntax error: identifier 'intmax_t'

wl2776
  • 3,454
  • 3
  • 24
  • 59
user1602
  • 1,542
  • 2
  • 14
  • 23

8 Answers8

73

The file include\pyport.h in Python installation directory does not have #include < stdint.h > anymore. This leaves intmax_t undefined.

A workaround for Microsoft VC compiler is to force include stdint.h via OS environment variable CL:

  1. Open command prompt
  2. Setup VC environment by runing vcvars*.bat (choose file name depending on VC version and architecture)
  3. set CL=-FI"Full-Path\stdint.h" (use real value for Full-Path for the environment)
  4. pip install pycrypto
user1602
  • 1,542
  • 2
  • 14
  • 23
  • Has this been patched into Windows Python? – CMCDragonkai Feb 15 '17 at 09:45
  • 10
    Why hasn't this been patched into Windows Python distribution? For the record, I was able to use vcvarsall.bat `C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat`. – CMCDragonkai Feb 15 '17 at 09:53
  • Has this been reported on the Python bug tracker? If so, can someone provide the reference? If not, maybe someone could do so. – Paul Moore Mar 19 '17 at 23:01
  • 2
    The issue was reported at https://github.com/dlitz/pycrypto/issues/221. The problem is with pycrypto itself, which supplies an incomplete ```stdint.h```, and I've added an explanation of the fix required to that bug report. – Paul Moore Mar 20 '17 at 14:39
  • Admin privileges are needed in case Python environment is in a protected/shared location – user1602 Jul 19 '17 at 01:43
  • I did not need admin privileges on Windows 7 with UAC. – Quolonel Questions Sep 09 '17 at 17:39
  • Try windows 10 and pip, not setup.py – user1602 Sep 10 '17 at 00:28
  • 6
    For me, steps 1+2 could be shortened to: **From Start menu, run "Visual C++ 2015 x86 Native Build Tools Command Prompt"** – akavel Dec 08 '17 at 00:34
  • 1
    also if you build it with **VS 2017**, the header location should be modified as follows: **set CL=-FI"%VCINSTALLDIR%\Tools\MSVC\14.16.27023\include\stdint.h** - of course _14.16.27023_ number depends on VS version, mine is 15.9. – Kasia Gauza Jan 14 '19 at 23:46
  • As of today, the best advice is to switch to pycryptodome. See bhuvan karuturi's answer – robertspierre Apr 10 '19 at 21:22
  • This worked for me in Windows 10 with Visual Studio 2019 (aka Visual Studio 14) using `set CL=-FI"%VCINSTALLDIR%\include\stdint.h"` – Stefan Mar 13 '20 at 18:45
33

I've succeeded install pycrypto 2.6.1 on python 3.6, Windows 10, Visual Studio 2017.

  1. Open "x86_x64 Cross-Tools Command Prompt for VS 2017" with administrator privilege in start menu.

  2. set CL=-FI"%VCINSTALLDIR%Tools\MSVC\14.11.25503\include\stdint.h"

  3. pip install pycrypto

enter image description here

Jossef Harush
  • 24,765
  • 7
  • 95
  • 103
Marko Rothstein
  • 401
  • 5
  • 5
  • 7
    Finally working solution!! Just make sure to check the actual version of MSVC folder, I had `14.12.25827`. Thanks mate – pagep Jan 09 '18 at 22:49
  • Thanks @Marko :-) For me these 3 command worked. 1. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build>vcvarsx86_amd64.bat 2. set CL=-FI"%VCINSTALLDIR%Tools\MSVC\14.16.27023\include\stdint.h" 3. pip install pycrypto==2.6.1 – dinu0101 Oct 04 '19 at 14:48
  • I'm thinking in Donate PayPal Button to this guy – Roberth Solís Oct 29 '20 at 23:20
22

Thanks to user1960422's answer.
PowerShell steps for pycrypto 2.6.1 (via simple-crypt) / Python 3.6 / Windows 10:

$env:VCINSTALLDIR="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC"
$env:CL="-FI`"$env:VCINSTALLDIR\INCLUDE\stdint.h`""

Successful simple-crypt / pycrypto install

I also needed to follow the answer in: https://stackoverflow.com/a/24822876/8751739 to fix a winrandom module error.

naaman
  • 737
  • 7
  • 11
  • That helped in PowerShell, but also I needed [Visual Studio can't build due to rc.exe](https://stackoverflow.com/questions/14372706/visual-studio-cant-build-due-to-rc-exe) for the linking to succeed. – Jari Turkia Feb 22 '18 at 15:33
  • visual studio 2017 build tools and in my case the VCINSTALLDIR is at VC\Tools\MSVC\14.16.27023 – Doogle Dec 18 '18 at 12:09
13

Use PyCryptodome instead of pycrypto. pycrypto is discontinued and is no longer actively supported. PyCryptodome exposes almost the same API as pycrypto (source).

robertspierre
  • 1,669
  • 1
  • 19
  • 23
bhuvan karuturi
  • 181
  • 1
  • 8
6

I've succeeded install pycrypo 2.6.1 on python 3.6 and windows 10.

  1. Set an environment variable like below. visual studio installed directory
  2. Open cmd.exe
  3. Activate virtualenv
  4. Download pycrypto 2.6.1 release from github and unzip it.
  5. set an environment variable for pycrypto set CL=/FI"%VCINSTALLDIR%\\INCLUDE\\stdint.h" %CL%
  6. Run setup command python setup.py install
  7. my result is here enter image description here

I would be glad if this could be help someone.

user1960422
  • 101
  • 1
  • 4
  • How is it different from the original answer? – user1602 Jul 15 '17 at 06:11
  • @user1602 you don't have to do the following steps in original answer --- 1. Open command prompt with admin privileges 2. Run vsvars32.bat from your version of VC – user1960422 Jul 16 '17 at 06:14
  • In your case you set VCINSTALLDIR manually, where I do it via vsvars32.bat. In the end you are suggesting the same solution. – user1602 Jul 19 '17 at 01:46
1
  • Uninstall your current Python version

  • Install Python for amd64 architecture

  • Follow the other accepted solutions:

    • open "x86_x64 Cross-Tools Command Prompt for VS 2017"
    • Add the new enviroment varible for your Visual Studio MSVC install path
    • set CL=-FI"%VCINSTALLDIR%Tools\MSVC\14.11.25503\include\stdint.h"
    • pip install pycrypto
Cool Cloud
  • 10,863
  • 3
  • 10
  • 32
1

For ppl who is encountering same situation as mine:

Env

  • Windows 10 Enterprise v10.0.18363 Build 18363
  • Python 3.8

Steps

  1. Download Microsoft C++ Build Tools at https://visualstudio.microsoft.com/visual-cpp-build-tools/
  2. Run above setup exe and install default components
    • MSVC v142 - VS 2019 C++ x64/x86 build tools
    • Windows 10 SDK
    • C++ CMake tools for windows
    • Testing tools core features - Build Tools
    • C++ AddressSanitizer(Experimental)
  3. Reboot PC
  4. Start menu > x64 Native Tools Command Prompt for VS 2019, a cmd window will pop up
  5. Execute set CL=-FI"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\stdint.h"
  6. Run pip install pycrypto in a cmd window(may need admin privilege) 1
Neo Tan
  • 11
  • 3
0

For me this fixes it:

with Python 2, I have

sudo apt-get install python-dev  \
     build-essential libssl-dev libffi-dev \
     libxml2-dev libxslt1-dev zlib1g-dev \
     ...

with Python 3, I need

sudo apt-get install python3 python-dev python3-dev \
     build-essential libssl-dev libffi-dev \
     ...

Installing python-dev python3-dev fixes it for me!

Jee Mok
  • 4,537
  • 7
  • 35
  • 66