python版本2.7.12
因为需要安装一个 pycrypto-2.7a1
下载的包为tar.gz
解压后 用CMD到达目录 执行
python setup.py install
发现报错 error: Unable to find vcvarsall.bat
C:\Users\VEADoc\Desktop\pycrypto-2.7a1> python setup.py install
running install
running build
running build_py
creating build
creating build\lib.win-amd64-2.7
creating build\lib.win-amd64-2.7\Crypto
copying lib\Crypto\pct_warnings.py -> build\lib.win-amd64-2.7\Crypto
copying lib\Crypto\__init__.py -> build\lib.win-amd64-2.7\Crypto
creating build\lib.win-amd64-2.7\Crypto\Hash
···中间省略一堆···
running build_ext
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Random.OSRNG.winrandom' extension
error: Unable to find vcvarsall.bat
如果没有下载
Microsoft Visual C++ Compiler Package for Python 2.7 请自行到微软官网下载
解决过程
找到这个 vsvarsall.bat 的文件
我是在 C:\Users\用户名\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\
文件夹下找到了 vcvarsall.bat
现在我们知道路径了。
接下去打开python安装目录下 Lib\distutils\ 文件夹下的 msvc9compiler.py 文件
搜索一下 vcvarsall 你就会找到几个相关的函数 并且知道是在哪里返回的路径
def query_vcvarsall(version, arch="x86"):
"""Launch vcvarsall.bat and read the settings from its environment
"""
vcvarsall = find_vcvarsall(version)
interesting = set(("include", "lib", "libpath", "path"))
result = {}
if vcvarsall is None:
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version)
popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
try:
stdout, stderr = popen.communicate()
if popen.wait() != 0:
raise DistutilsPlatformError(stderr.decode("mbcs"))
stdout = stdout.decode("mbcs")
for line in stdout.split("\n"):
line = Reg.convert_mbcs(line)
if '=' not in line:
continue
line = line.strip()
key, value = line.split('=', 1)
key = key.lower()
if key in interesting:
if value.endswith(os.pathsep):
value = value[:-1]
result[key] = removeDuplicates(value)
finally:
popen.stdout.close()
popen.stderr.close()
if len(result) != len(interesting):
raise ValueError(str(list(result.keys())))
return result
看代码可知 vcvarsall 变量是在 query_vcvarsall() 这个函数下定义的,既然程序他自己找不到,那我们就告诉他
注释掉标红的原赋值语句,自己把刚刚找到的文件夹路径写进去
vcvarsall = r"C:\Users\用户名\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat"
保存后。重新安装包
python setup.py install
会发现 顺利完成了
最后。。记得把刚刚更改的 msvc9compiler.py 文件复原。毕竟是python自带的 改了不知道会不会出乱子