问题描述

在windows 10上使用python 3.6。在安装pycrypto库时,出现了以下错误

error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

解决方案

这是由于python安装库include/pyport.h没有#include <stdint.h>,这导致intmax_t未定义。

Microsoft VC编译器的解决方法是通过OS环境变量CL强制包含stdint.h。
步骤如下:

  • 打开命令提示符cmd,通过运行 vcvars*.bat(不同的VC版本和架构名称可能不通)启动VC环境。

    cd C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>vcvarsall.bat
  • set CL=-FI"Full-Path\stdint.h" (Full-Path使用真实环境变量值)

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>set CL=-FI"%VCINSTALLDIR%\INCLUDE\stdint.h"

这里的%VCINSTALLDIR%就是VC的安装目录,我的系统中为

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\
  • 再次尝试安装pycrypto
    E:\Workplace\Python\project> pip install pycrypto
    Collecting pycrypto
    Using cached https://files.pythonhosted.org/packages/60/db/645aa9af249f059cc3a368b118de33889219e0362141e75d4eaf6f80f163/pycrypto-2.6.1.tar.gz
    Installing collected packages: pycrypto
    Running setup.py install for pycrypto ... done
    Successfully installed pycrypto-2.6.1

不过目前pycrypto库似乎已经停止更新维护,可以选择其它的加密库了。

最后修改:2020 年 04 月 30 日 10 : 07 PM