最近接触公司后台管理系统的开发,其中涉及到加密模块pycrypto。
重点来了!!!!敲黑板!!!!
pycrypto在PyCharm中跟其他的模块不一样,pip install pycrypto安装的是1.4.1版本,然后虽然模块能够install成功,但实际上代码还是无法关联起来,运行会报异常。
百度解决方案:下载pycrypto源码安装
不过安装pycrypto源码可不是这么简单的事情,这里把这几天踩过的坑都记录一下。

1.下载pycrypto源码
官网:https://www.dlitz.net/software/pycrypto/
github:https://github.com/dlitz/pycrypto
下载源码解压,win+R运行cmd,进入解压文件夹

python setup.py install
1
如果没有报错误,看到

running install_egg_info
1
恭喜你,不用踩坑,直接可以关闭这篇东西去愉快地写代码了

2.安装过程中显示unable to find vcvarsall.bat
这是window环境下安装模块比较常见的问题,这时候你百度的话大部分文章就会告诉你下载vs,python2的话安装vs2010,python3的话安装vs2013
重点!!!!!!!!
不要着急去安装vs,这东西一安装就是好几个小时,在这里我对vs装了卸,卸了装浪费了一天半的时间。
python有个深坑!不同的python版本对应不同的vs版本,具体对应的版本在python所在的路径下\Lib\distutils_msvccompiler.py
比如我的路径是E:\Python\Python36\Lib\distutils_msvccompiler.py
打开找到def _find_vcvarsall(plat_spec)
这个函数下有个if version >= 14 and version > best_version

这里的version >= 14就是对应的vs版本号,如果你跟我一样是python3.6的话应该这里是14,之前就是看到其他的博客,没有查看这里的版本号就装,先是装了vs2010,然后装2013,再卸了装了对应版本号的vs2015,其中vs的版本号对应关系如下:
msvs2005版本号为8.0,对应环境变量VS80COMNTOOLS
msvs2008版本号为9.0,对应环境变量VS90COMNTOOLS
msvs2010版本号为10.0,对应环境变量VS100COMNTOOLS
msvs2012版本号为11.0,对应环境变量VS110COMNTOOLS
msvs2013版本号为12.0,对应环境变量VS120COMNTOOLS
msvs2015版本号为14.0,对应环境变量VS140COMNTOOLS

3.安装对应版本的msvs(Microsoft Visual Studio)
如果是Visual Studio 2015,提供个百度经验上百度网盘给大家
http://pan.baidu.com/s/1eSueWLG
如果不需要用vs进行开发的话,装community免费版就可以了,没必要纠结专业版啥的
安装过程中要注意,建议安装的时候选自定义(截图来自百度经验,因为已经安装了打开之后有点不太一样)

记得勾选VC++2015和Python Tools。Web Deveolper Tools的话最好也勾上吧。
但我的安装过程没这么顺利,泪奔~

安装部分模块失败,然后我重新安装。因为主要的vs2015安装是成功的,所以只勾选

VC++2015
Python Tools
Web Deveolper Tools
这三个模块,500M左右,重新安装就提示全部成功了
很多人说装完之后要改环境变量,
 python2:set VS90COMNTOOLS=%VS140COMNTOOLS%
 python3:set VS100COMNTOOLS=%VS140COMNTOOLS%
1
2
可能python3.6版本高了不需要这样,不过也记录一下给各位看官仅供参考。反正我是不需要改,因为接下来我踩了另一个坑
再次进入pycryto的解压文件夹python setup.py install 仍然显示
building ‘Crypto.Random.OSRNG.winrandom‘ extension

running install
running build
running build_py
running build_ext
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
building ‘Crypto.Random.OSRNG.winrandom‘ extension
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc/ -Isrc/inc-msvc/ -IC:\Python36\include -IC:\Python36\include
winrand.c
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(26): error C2061: syntax error: identifier ‘intmax_t‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(27): error C2061: syntax error: identifier ‘rem‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(27): error C2059: syntax error: ‘;‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(28): error C2059: syntax error: ‘}‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(30): error C2061: syntax error: identifier ‘imaxdiv_t‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(30): error C2059: syntax error: ‘;‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(40): error C2143: syntax error: missing ‘{‘ before ‘__cdecl‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(41): error C2146: syntax error: missing ‘)‘ before identifier ‘_Number‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(41): error C2061: syntax error: identifier ‘_Number‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(41): error C2059: syntax error: ‘;‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(42): error C2059: syntax error: ‘)‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(45): error C2143: syntax error: missing ‘{‘ before ‘__cdecl‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(46): error C2146: syntax error: missing ‘)‘ before identifier ‘_Numerator‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(46): error C2061: syntax error: identifier ‘_Numerator‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(46): error C2059: syntax error: ‘;‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(46): error C2059: syntax error: ‘,‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(48): error C2059: syntax error: ‘)‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(50): error C2143: syntax error: missing ‘{‘ before ‘__cdecl‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(56): error C2143: syntax error: missing ‘{‘ before ‘__cdecl‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(63): error C2143: syntax error: missing ‘{‘ before ‘__cdecl‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(69): error C2143: syntax error: missing ‘{‘ before ‘__cdecl‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(76): error C2143: syntax error: missing ‘{‘ before ‘__cdecl‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(82): error C2143: syntax error: missing ‘{‘ before ‘__cdecl‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(89): error C2143: syntax error: missing ‘{‘ before ‘__cdecl‘
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(95): error C2143: syntax error: missing ‘{‘ before ‘__cdecl‘
error: command ‘C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe‘ failed with exit status 2

4.解决building ‘Crypto.Random.OSRNG.winrandom‘ extension
1.添加VC环境变量,设置用户环境变量,这里划重点!!!是用户环境变量,不是系统环境变量

变量名:VCINSTALLDIR
(变量值为vs安装路径下的VC,默认是这个)
变量值:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC
2. win+R运行cmd,执行命令set CL=/FI”%VCINSTALLDIR%\INCLUDE\stdint.h” %CL%
3. 再次进入pycryto的解压文件夹python setup.py install ,看到
能显示running install_egg_info 就是安装成功了

5.注意是Crypto还是crypto,区分大小写
我这里安装成功之后代码alt+enter自动关联的是

from crypto.Cipher import AES
1
然后代码运行报错,点进去AES里面import的是

from Crypto.Cipher import _AES
1
小伙伴如果遇到跟我一样的问题,可以手动进入python\Lib下,我的路径是
E:\Python\Python36\Lib
然后把文件夹crypto改成Crypto。把小写改成大写,刷新下,完美运行~~~~

pycrypto安装错误相关推荐

  1. 傻瓜式解决pycrypto安装错误

    替换为豆瓣源 仅解决错误为error: Microsoft Visual C++ 14.0 is required时,cmd中错误情况如下图所示: 解决方法: 将 pip install pycryp ...

  2. pycrypto打包错误

    使用改方法仍然报错,对win10_SDK进行升级,升级后安装正常.​​​​​​pycrypto打包错误_Py-Jun的博客-CSDN博客 sdk安装包 winsdksetup C:\Program F ...

  3. git安装+错误:Failed to install ‘IRkernel‘ from GitHub: Git does not seem to be installed on your system

    git安装+错误:Failed to install 'IRkernel' from GitHub: Git does not seem to be installed on your system ...

  4. 解决Adobe Reader安装错误150120

    今天Adobe Reader这个软件提示有新版本了,让我更新,出于信任,我不假思索地更新了Adobe Reader这个软件,于是我倒霉的一天就在这之后了. 我用这个软件打开赛灵思的DocNav里面的赛 ...

  5. oracle 安装程序异常终止,Oracle安装错误“程序异常终止

    Oracle安装错误"程序异常终止.发生内部错误.请将以下文件提供给oracle技术支持部 "程序异常终止.发生内部错误.请将以下文件提供给oracle技术支持部门: " ...

  6. matplotlib安装错误依赖问题解决

    matplotlib安装错误依赖问题解决 参考文章: (1)matplotlib安装错误依赖问题解决 (2)https://www.cnblogs.com/jonky/p/10155308.html ...

  7. Oracle安装错误“程序异常终止

    Oracle安装错误"程序异常终止 参考文章: (1)Oracle安装错误"程序异常终止 (2)https://www.cnblogs.com/amwuau/p/6255498.h ...

  8. oracle11g +WindoWs7 安装错误:未找到文件WFMLRSVCApp.ear

    oracle11g +WindoWs7 安装错误:未找到文件WFMLRSVCApp.ear 将win64_11gR2_database_1of2.zip和win64_11gR2_database_2o ...

  9. Mysql5.7安装错误处理与主从同步及!

    Mysql5.7安装错误处理与主从同步及! basedir=/iddbs/mysql-5.7.16 datadir=/iddbs/mysql5.7/data3306 一.自定义Mysql.5.7版本免 ...

最新文章

  1. 日常工作问题解决:rhel7下配置多路径设备
  2. java性能调优指南,帮你解决90%的问题!
  3. CentOS忘记密码
  4. 很多人都不知道的小秘密,c++中拷贝分为两种
  5. 应用Rational 工具简化基于J2EE的项目(二)启动项目
  6. 自动从mysql下载文件到powerbi_关于在Power Query和Power BI中从网页下载文件的小提示...
  7. 十六、深入Python字符串
  8. Linux学习之CentOS(三十)--SELinux安全系统基础
  9. an example of Ascii using 问号 as example
  10. 炒菜机器人的弊端_机器人炒菜真不是你想的那样!
  11. shell find命令 文件夹查询关键字 查询结果输出新文件
  12. java applog_Java Web App: 选择与配置日志库
  13. Python进阶丨如何创建你的第一个Python元类?
  14. nginx(4、缓存)
  15. a点到b点最短路线有多少条_8下数学培优:几何体上最短路径问题,总结与提升,不一样的感受...
  16. cenos回到linux桌面快捷键,CentOS 常用命令及快捷键整理
  17. GitHub上传代码及在线demo演示
  18. less css基础教程
  19. Java xml格式化工具
  20. RSA生成公私钥并加解密

热门文章

  1. 公司要倒闭遣散员工要如何处理
  2. iPhone 6 上市时间有可能定于 8 月?
  3. 用Spire.XLS给Excel添加水印,打印水印
  4. 骁龙8 gen2和天玑8100哪个好 高通骁龙8gen2和天玑8100参数对比
  5. 如何干掉VIVO手机安装验证这个脑残一般的设定(已解决)
  6. macOS Monterey 系统关闭SIP详细教程,超级简单!
  7. Flink CDC 在京东的探索与实践
  8. Excel转CSV分隔符问题
  9. 华为荣耀八手机经常显示无服务器,华为荣耀8手机为什么跳屏
  10. 李子柒与袁隆平同台获奖,程序员表示:我们太像了!