Windows 安装 pycrypto 常见问题解决,


首先pycrypto 项目已经不在更新了,自己开发可以使用cryptography、pycryptodome

https://pypi.org/project/cryptography/
https://pypi.org/project/pycryptodome/

关于python使用Crypto.Cipher模块,安装pycrypto ,ImportError: No module named 'Crypto'  常见问题及解决方案如下:

 

1.  需要安装:Microsoft Visual C++ 14.0

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

安装VC

只要版本大于等于Microsoft Visual C++ 14.0  就可以,对应的VS版本高于2015就可以

微软官方VC下载地址

https://learn.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist?view=msvc-170

也可以安装vs 桌面版本,会自动安装VC,相对会比较大,下载Community版本即可,安装时"使用c++的桌面开发"

微软官网下载地址

https://visualstudio.microsoft.com/zh-hans/ 

https://my.visualstudio.com/Downloads?q=visual%20studio%202019&wt.mc_id=o~msft~vscom~older-downloads

 

2. 安装VC 以后,inttypes.h 报错

报错信息:

ucrt\inttypes.h(26): error C2061: syntax error: identifier ‘intmax_t‘

error C2061: 语法错误: 标识符“intmax_t”;
error C2059: 语法错误:“;” ;
error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)

 

以下两种方案都可以使用

解决办法1:手动修改默认vs文件

(1) 复制 stdint.h到系统目录下
# 默认路径如下,注意自己安装vs的实际路径
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\include\stdint.h
到
C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\下

(2) 修改inttypes.h文件,
C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\inttypes.h
将第13行
#include <stdint.h>
修改为
#include "stdint.h"

(3) 重新安装 pycrypto

 

解决方法2:设置vs环境变量

# cmd 下执行
cd \
cd C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC
vcvarsall.bat x86_amd64 

-----------
# PyCharm 终端下执行

# 设置 stdint.h
set CL=-FI"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\stdint.h"
# 安装pycrypto 
pip install pycrypto

 

 

3. Crypto首字母大小写问题

代码中引用Crypto 首字母大写,实际安装后模块目录下 Lib/site-packages/crypto  目录是小写,可以直接将该目录改成首字母大写的Crypto

 

评论关闭