须要安装 Microsoft Visual Studio2017 Community 或者buildtoolspython
1.设置Microsoft Visual Studio 14.0的环境变量 VCINSTALLDIR 变量值 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC(默认安装位置,请根据本身的安装位置肯定)如图:git
2.在上面安装路径中执行 vcvarsall.bat 脚本github
3.在命令行(cmd)中执行 set CL=-FI"%VCINSTALLDIR%\INCLUDE\stdint.h"dom
4.从新安装 pip install pycryptoide
5.安装好后,须要进入Lib\site-packages\文件夹中将文件夹crypto 的第一个字母变为大写 "Crypto"(切记切记,不然代码会告诉import不成功)函数
(1)本机上安装了Microsoft Visual Studio2017 Community版ui
A、将D:\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\目录下加密
B、修改C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\inttypes.h中的第13行,将spa
修改成.net
--------------------
最近接触公司后台管理系统的开发,其中涉及到加密模块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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 _AES1小伙伴若是遇到跟我同样的问题,能够手动进入python\Lib下,个人路径是 E:\Python\Python36\Lib 而后把文件夹crypto改为Crypto。把小写改为大写,刷新下,完美运行~~~~--------------------- 做者:孤影惆怅 来源:CSDN 原文:https://blog.csdn.net/a624806998/article/details/78596543 版权声明:本文为博主原创文章,转载请附上博文连接!