我是在win11, python3.6基础上安装pycrypto报错的,使用的安装命令为:?'pip install pycrypto' 。
D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Isrc/ -Isrc/inc-msvc/ -Ic:\python368\include -Ic:\python368\include "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\ATLMFC\include" "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-ID:\Windows Kits\10\include\10.0.19041.0\ucrt" "-ID:\Windows Kits\10\\include\10.0.19041.0\\shared" "-ID:\Windows Kits\10\\include\10.0.19041.0\\um" "-ID:\Windows Kits\10\\include\10.0.19041.0\\winrt" "-ID:\Windows Kits\10\\include\10.0.19041.0\\cppwinrt" /Tcsrc/winrand.c /Fobuild\temp.win32-3.6\Release\src/winrand.obj
winrand.c
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(31): error C2061: 语法错误: 标识符“intmax_t”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(32): error C2061: 语法错误: 标识符“rem”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(32): error C2059: 语法错误:“;”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(33): error C2059: 语法错误:“}”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(35): error C2061: 语法错误: 标识符“imaxdiv_t”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(35): error C2059: 语法错误:“;”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(45): error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(46): error C2146: 语法错误: 缺少“)”(在标识符“_Number”的前面)
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(46): error C2061: 语法错误: 标识符“_Number”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(46): error C2059: 语法错误:“;”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(47): error C2059: 语法错误:“)”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(50): error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(51): error C2146: 语法错误: 缺少“)”(在标识符“_Numerator”的前面)
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(51): error C2061: 语法错误: 标识符“_Numerator”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(51): error C2059: 语法错误:“;”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(51): error C2059: 语法错误:“,”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(53): error C2059: 语法错误:“)”
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(55): error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(61): error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(68): error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(74): error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(81): error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(87): error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(94): error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)
D:\Windows Kits\10\include\10.0.19041.0\ucrt\inttypes.h(100): error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)
error: command 'D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.30.30705\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
----------------------------------------
Command "c:\python368\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\cosseen\\AppData\\Local\\Temp\\pip-install-wjk8w2u4\\pycrypto\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\cosseen\AppData\Local\Temp\pip-record-pk6psnb1\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\cosseen\AppData\Local\Temp\pip-install-wjk8w2u4\pycrypto\
解决办法:
1. 设置编译的环境,在native tools command基础上,再次运行vcvars*.bat。我本地的脚本为D:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\vsdevcmd\ext\vcvars.bat。运行时,最好输入绝对路径。
2. 添加CL参数set CL=-FI"Full-Path\stdint.h" (替换红色部分为自己的目录)
set CL=-FI"%VCINSTALLDIR%\INCLUDE\stdint.h"
也可以使用绝对路径
set CL=-FI"D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include\stdint.h"
3. 再次执行安装命令,安装成功。?
D:\Program Files\Microsoft Visual Studio\2022\Community>pip install pycrypto
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Collecting pycrypto
Downloading http://mirrors.aliyun.com/pypi/packages/60/db/645aa9af249f059cc3a368b118de33889219e0362141e75d4eaf6f80f163/pycrypto-2.6.1.tar.gz (446kB)
100% |████████████████████████████████| 450kB 14.6MB/s
Installing collected packages: pycrypto
Running setup.py install for pycrypto ... done
Successfully installed pycrypto-2.6.1
另外,最好使用PyCryptodome 代替pycrypto,pycrypto不再维护了,而PyCryptodome的API和
pycrypto的相同。
|