easy_install和pip都是用来下载安装Python一个公共资源库PyPI的相关资源包的管理工具,而pip是easy_install的改进版,提供更好的提示信息,删除package等功能。Python官网上编译好的msi文件已经包含这两个工具,安装在<Python安装目录>/lib/site-packages文件中。
系统环境是win7(64bit)+python2.7.10(64bit)+vs2010,在此记录使用pip安装numpy过程中出现的问题及解决方法。
1 Unable to find vcvarsall.bat
打开powershell,(事先将Python以及Python的Script的目录导入环境变量PATH中),输入:
pip install numpy
出现错误:
Setup script exited with error: Unable to findvcvarsall.bat
【原因分析】
Setupscript exited with error: Unable to find vcvarsall.batThePython package being installed contains the source code for a native extensionmodule (.pyd), but does not have a pre-built copy of the module. ThePython packages highlighted at pythonwheels.com have already been updated by theirdevelopers to include pre-built binaries, but many are still only available assource code.(来自微软官网)
即需要编译的代码中用到了C的代码,而这个包的代码发布的时候没有预先编译成Python的二进制文件,所以安装过程中需要使用C complier 编译这些模块。在Windows下,Python的setup.py需要Visual Studio2008的支持。
【解决方法】
(1)如果你的机器上有更高版本的VS,可以通过下面的方式让Python使用更新版本的VS来支持安装。
如果你的机器上装了VisualStudio 2010,可以在执行pip install之前先执行下面的命令:
SET VS90COMNTOOLS=%VS100COMNTOOLS%
如果你安装了VisualStudio2012可以执行下面命令:
SET VS90COMNTOOLS=%VS110COMNTOOLS%
如果你装的vs版本是2013可以使用下面命令:
SET VS90COMNTOOLS=%VS120COMNTOOLS%
(2)如果没有Microsoft的VS环境,可以安装 Microsoft Visual C++ Compiler for Python 2.7 。
2 cannot link a simple C program
问题1排除后继续安装过程,出现错误:
RuntimeError: Broken toolchain: cannot link asimple C program
【解决方法】
在路径%PythonHome%Lib\distutils(默认是C:\Python27\Lib\distutils)中的msvc9compiler.py文件大约661行处,如下图修改:
重新输入命令
pip install numpy
安装成功:
【参考资料】
http://www.tuicool.com/articles/JzI3Uj
http://blog.csdn.net/yanqiangsdu/article/details/43166951