安装PyCrypto时VS编译出错

前言

最近做了个project,需要用到PyCrypto。

PyCrypto在Windows下需要使用VC进行编译,不过Python模块在Windows平台编译坑点比较多。

如:

winrand.c

D:\Windows Kits\10\include\10.0.17134.0\ucrt\inttypes.h(27): error C2061: 语法错误: 标识符“intmax_t”

D:\Windows Kits\10\include\10.0.17134.0\ucrt\inttypes.h(28): error C2061: 语法错误: 标识符“rem”

D:\Windows Kits\10\include\10.0.17134.0\ucrt\inttypes.h(28): error C2059: 语法错误:“;”

D:\Windows Kits\10\include\10.0.17134.0\ucrt\inttypes.h(29): error C2059: 语法错误:“}”

D:\Windows Kits\10\include\10.0.17134.0\ucrt\inttypes.h(31): error C2061: 语法错误: 标识符“imaxdiv_t”

D:\Windows Kits\10\include\10.0.17134.0\ucrt\inttypes.h(31): error C2059: 语法错误:“;”

D:\Windows Kits\10\include\10.0.17134.0\ucrt\inttypes.h(41): error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)

D:\Windows Kits\10\include\10.0.17134.0\ucrt\inttypes.h(42): error C2146: 语法错误: 缺少“)”(在标识符“_Number”的前面)

... blah blah blah ...

解决方案

查看原文。vs安装pycrypto-2.6.1报错处理_因上努力 ,果上随缘-CSDN博客

处理方式:

修改文件 setup.py

def detect_modules (self):

    # Read the config.h file (usually generated by autoconf)

    if self.compiler.compiler_type == 'msvc' and False:

        # Add special include directory for MSVC (because MSVC is special)

        self.compiler.include_dirs.insert(0, "src/inc-msvc/")

        ac = self.__read_autoconf("src/config.h")

    else:

        ac = self.__read_autoconf("src/config.h")

在if self.compiler.compiler_type == 'msvc'后加上and False,使special失效。

然后拷贝\src\inc-msvc\config.h 到\src\config.h 编译即可。

#python

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容