python 加密模块安装
我们使用Python做加密算法如AES、MD5、SHA等时,需要用到PyCrypto模块
PyCrypto模块的安装方法
1、一般在官方网站下载:
在安装一些Python模块时,大部分是cpython写的模块时会发生如下错误 error: Unable to find vcvarsall.bat。先前的一篇文章:在Windows上安装Scrapy时也讲到了这个问题。当时讲到的方案是,安装VS 2008进行解决,但是Vs 2008又太大,不想装,所以这次想到了另外的方案,同样是上次说的,当时上次很不完整。
方案一:安装Vs2008(实测)
完全的无脑流,安装完问题直接解决。
方案二:安装Vs2010(2016-1-29更新)
上次在电脑上装个Vs2010并不能像 vs2008那样直接解决问题,主要原因是Python 2.7 使用的是 VS 2008编译的,所以Python 2.7默认只能认出VS 2008。
解决办法,在命令行下执行 SET VS90COMNTOOLS=%VS100COMNTOOLS%
- VS 2010 对应:SET VS90COMNTOOLS=%VS100COMNTOOLS%
- VS 2012 对应:SET VS90COMNTOOLS=%VS110COMNTOOLS%
- VS 2013 对应:SET VS90COMNTOOLS=%VS120COMNTOOLS%
或者通过修改Python的源代码进行修改:打开“<python安装目录>\Lib\distutils\msvc9compiler.py”,找到 toolskey = “VS%0.f0COMNTOOLS” % version,直接修改为 toolskey = “VS100COMNTOOLS”
如果是Python 3,则上面的方法是无效的,原因是Python 3使用的是VS 2010编译的,所以设置应该是这样:
- VS 2010 无需设置,直接能认出
- VS 2012 对应:SET VS100COMNTOOLS=%VS110COMNTOOLS%
- VS 2013 对应:SET VS100COMNTOOLS=%VS120COMNTOOLS%
或修改msvc9compiler.py文件,将: vc_env = query_vcvarsall(VERSION, plat_spec) 中的VERSION设定为已安装的VS版本对应的值:
- VS2008,则VERSION为9.0
- VS2010,则VERSION为10.0
- VS2012,则VERSION为11.0
- VS2013,则VERSION为12.0
- VS2014,则VERSION为13.0
注意:Python 3.5升级了distutils,默认使用_msvccompiler.py,在这个文件中可以找到:“ if version >= 14 and version > best_version: ”这里的14说明VS版本要在14以上才可以。所以根据这句,我们要安装最新的Visual Studio2015。上面修改msvc9compiler.py的办法没有效果。
另外,微软也提供了解决方案:
| Python Version | You will need |
| 3.5 and later | Visual C++ Build Tools 2015 or Visual Studio 2015 |
| 3.3 and 3.4 | Windows SDK for Windows 7 and .NET 4.0 (Alternatively, Visual Studio 2010 if you have access to it) |
| 2.6 to 3.2 | Microsoft Visual C++ Compiler for Python 2.7 |
参考链接:https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/
1.下载完成并安装。以本机为例,安装完成后的路径为:
|
1
|
C:\Users\Administrator\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0 |
2.修改python安装目录下Lib\distutils\msvc9compiler.py文件(如有必要可能msvccompiler.py文件也需要做相应更改,视系统而定),找到get_build_version方法直接return 9.0
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
def get_build_version(): """Return the version of MSVC that was used to build Python. For Python 2.3 and up, the version number is included in sys.version. For earlier versions, assume the compiler is MSVC 6. """ return 9.0 prefix = "MSC v." i = sys.version.find(prefix) if i == -1: return 6 i = i + len(prefix) s, rest = sys.version[i:].split(" ", 1) majorVersion = int(s[:-2]) - 6 minorVersion = int(s[2:3]) / 10.0 # I don't think paths are affected by minor version in version 6 if majorVersion == 6: minorVersion = 0 if majorVersion >= 6: return majorVersion + minorVersion # else we don't know what version of the compiler this is return None |
然后再找到find_vcvarsall方法直接返回vcvarsall.bat的路径(以自己机器安装后的路径为准)
|
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
35
36
37
38
39
40
41
42
43
44
|
def find_vcvarsall(version): """Find the vcvarsall.bat file At first it tries to find the productdir of VS 2008 in the registry. If that fails it falls back to the VS90COMNTOOLS env var. """ return r'C:\Users\Administrator\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat' vsbase = VS_BASE % version try: productdir = Reg.get_value(r"%s\Setup\VC" % vsbase, "productdir") except KeyError: productdir = None # trying Express edition if productdir is None: vsbase = VSEXPRESS_BASE % version try: productdir = Reg.get_value(r"%s\Setup\VC" % vsbase, "productdir") except KeyError: productdir = None log.debug("Unable to find productdir in registry") if not productdir or not os.path.isdir(productdir): toolskey = "VS%0.f0COMNTOOLS" % version toolsdir = os.environ.get(toolskey, None) if toolsdir and os.path.isdir(toolsdir): productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC") productdir = os.path.abspath(productdir) if not os.path.isdir(productdir): log.debug("%s is not a valid directory" % productdir) return None else: log.debug("Env var %s is not set or invalid" % toolskey) if not productdir: log.debug("No productdir found") return None vcvarsall = os.path.join(productdir, "vcvarsall.bat") if os.path.isfile(vcvarsall): return vcvarsall log.debug("Unable to find vcvarsall.bat") return None |
3.上述完成之后就可以在windwos下正常编译python的C扩展。以pycrypto-2.6.1为例,执行如下命令
|
1
|
python setup.py install |
当然也可以建立一个windows的二进制包
|
1
|
python setup.py bdist_wininst |
python 加密模块安装的更多相关文章
- Python的安装和详细配置
Python是一种面向对象.解释型计算机程序设计语言.被认为是比较好的胶水语言.至于其他的,你可以去百度一下.本文仅介绍python的安装和配置,供刚入门的朋友快速搭建自己的学习和开发环境.本人欢迎大 ...
- python requests 安装
在 windows 系统下,只需要输入命令 pip install requests ,即可安装. 在 linux 系统下,只需要输入命令 sudo pip install requests ,即可 ...
- Python 的安装与配置(Windows)
Python2.7安装配置 python的官网地址:https://www.python.org/ 我这里下载的是python2.7.12版本的 下载后点击安装文件,直接点击下一步知道finally完 ...
- 初学python之安装Jupyter notebook
一开始安装python的时候,安装的是最新版的python3.6的最新版.而且怕出问题,选择的都是默认安装路径.以为这样总不会出什么问题.一开始确实这样,安装modgodb等一切顺利.然而在安装jup ...
- 转: python如何安装pip和easy_installer工具
原文地址: http://blog.chinaunix.net/uid-12014716-id-3859827.html 1.在以下地址下载最新的PIP安装文件:http://pypi.python. ...
- CentOS 6.5升级Python和安装IPython
<转自:http://www.noanylove.com/2014/10/centos-6-5-sheng-ji-python-he-an-zhuang-ipython/>自己常用.以做备 ...
- python Scrapy安装和介绍
python Scrapy安装和介绍 Windows7下安装1.执行easy_install Scrapy Centos6.5下安装 1.库文件安装yum install libxslt-devel ...
- window下从python开始安装科学计算环境
Numpy等Python科学计算包的安装与配置 参考: 1.下载并安装 http://www.jb51.net/article/61810.htm 1.安装easy_install,就是为了我们安装第 ...
- Python virtualenv安装库报错SSL: CERTIFICATE_VERIFY_FAILED
Python virtualenv安装库报错SSL: CERTIFICATE_VERIFY_FAILED 问题描述 使用pip按照virtualenv报错,如下: pip install virtua ...
随机推荐
- mysql 查询表
判断表是否存在 SELECT table_name FROM information_schema.TABLES WHERE table_name ='yourname'; 判断存储过程是否存在 se ...
- 在类库中使用log4net
最近在做一个类库,用的C#写的,为了DEBUG方便需要日志输出,于是找了log4net这个工具进行日志输出; 因为调用这个类库的是C++,而且本人对C++不是很熟悉,于是无法在app.config或者 ...
- Qt多国语言QT_TR_NOOP和QT_TRANSLATE_NOOP
文章来源:http://devbean.blog.51cto.com/448512/245063/ 在代码中,我们使用tr()将需要翻译的字符串标记出来.lupdate工具就是提取出tr()函数中的相 ...
- PHP关于时区问题
最近在学习PHP过程中发现PHP中的格式化时间戳比北京时间晚了8个小时,上网搜索发现原来是时区不对,解决办法是: 1.永久修改 更改php.ini文件中的data.tim ...
- 2015.11.27初识java一集简单的java小程序
JAVA配置环境变量方法: 1.打开我的电脑--属性--高级--环境变量 2.新建系统变量JAVA_HOME 和CLASSPATH 变量名:JAVA_HOME变量值:D:\Java\jdk1.7.0_ ...
- inline-block及解决空白间距
參考:http://www.jb51.net/css/76707.html http://www.webhek.com/remove-whitespace-inline-block/ inline-b ...
- 在Unity中使用Shader
1.Material 和 Shader 的关系.一个材质包括一个Shader程序.在Shader中设置的属性能够通过Material可视化设置 2.内建Shader,在5.0之后的版本号中大部分旧的S ...
- [AngularJS + RxJS] Search with RxJS
When doing search function, you always need to consider about the concurrent requests. AEvent ----(6 ...
- 使用Qt Style Sheets制作UI特效
引言 作为一套GUI框架,Qt是非常强大的.(注:Qt 不仅是一套优秀的GUI框架,同时也是一套出色的应用程序框架).在UI的制作方面Qt为广大开发者提供了一套强大而易用的工具,她就是——Qt Sty ...
- webform开发经验(一):Asp.Net获取Checkbox选中的值
webform中获取repeat控件列表下的checkbox选中的值: 码农上代码: public static string getSelectedIDs(Repeater Rpt_) { stri ...