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 ...
随机推荐
- 再转一篇gtest1.6安装
http://www.cppblog.com/izualzhy/archive/2012/07/31/185772.html googletest是一个用来写C++单元测试的框架,它是跨平台的,可应用 ...
- repo init 时gpg: 无法检查签名:找不到公钥
i found a solution here: http://www.marshut.com/wrrts/repo-release-1-12-4.html Sorry, I realized tod ...
- XJOI网上同步训练DAY6 T1
思路:考试的时候直接想出来了,又有点担心复杂度,不过还是打了,居然是直接A掉,开心啊. 我们发现,Ai<=7,这一定是很重要的条件,我们考虑状态压缩,去枚举路径中出现了哪些数字,然后我们把原来n ...
- Linux环境下使用JFS文件系统
Linux环境下使用JFS文件系统 JFS是IBM公司为linux系统开发的一个日志文件系统.从IBM的实力及它对Linux的态度来看,JFS应该是未来日志文件系统中最具实力的一个文件系统. JFS提 ...
- hdu4085
http://acm.hdu.edu.cn/showproblem.php?pid=4085 斯坦纳树. 用状压DP. 一共有2K个关键点:1,2...,K和N-K+1,N-K+2...,N,我们用一 ...
- HTML5 拼图游戏
点击之后被选中的切片会变为透明 源代码 点击打开链接
- Android Studio:Unable to add window android.view.ViewRootImpl$W@5e2d85a -- permission denied for this window 第一行代码
学习<第一行代码>的时候,出现的错误. java.lang.RuntimeException: Unable to start receiver com.example.sevenun.l ...
- testng xml 示例
TestNG的DTD检查文件:http://testng.org/testng-1.0.dtd.php 更多testng配置及说明,请移步http://testdoc.org/docmaster?pi ...
- Fragment的简单使用
最近一直有点忙,刚刚看到一个朋友的留言提到Fragment中加载ListView的问题,这里写了一个非常简单的测试,至于对Fragment的增.删.改实现动态布局构建灵活的UI,以后有时间在讨论: M ...
- opencv 实现进度控制
进度控制: #include <opencv\cv.h> #include <opencv\highgui.h> #include <opencv\cxcore.h> ...