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

1
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

https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/

也可以安装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 报错

报错信息:

1
2
3
4
5
ucrt\inttypes.h(26): error C2061: syntax error: identifier ‘intmax_t‘
 
error C2061: 语法错误: 标识符“intmax_t”;
error C2059: 语法错误:“;” ;
error C2143: 语法错误: 缺少“{”(在“__cdecl”的前面)

 

以下两种方案都可以使用

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
(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环境变量

1
2
3
4
5
6
7
8
9
10
11
12
# 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

 

posted @   i学笔记  阅读(808)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示