search
HomeBackend DevelopmentPython TutorialPython3.4 用 pip 安装lxml时出现 “Unable to find vcvarsall.bat ”?

我在网上搜了好多,说需要安装 vs2008,但是我安装了vs2008专业版,依然还是这个问题“Unable to find vcvarsall.bat ”
再然后,我又照网上说的下载安装MinGW了,并且修改了环境变量等一系列东西,最后错误又变成了“TypeError: unorderable types: NoneType() >= str()”
请问这个到底该怎么解决?

回复内容:

刚从这个大坑里爬出来:


1. 安装wheel,命令行运行:

pip install wheel
建议直接装编译好的安装包:
lfd.uci.edu/~gohlke/pyt !!!!python35已不适用以下方案

----------原答案-----------
C:/Python31/Lib/distutils目录下,发现“unable to find vcvarsall.bat”这句话在msvc9compiler.py中
问题出在构建python的版本和你计算机上安装的版本可能不一样。
具体修改代码如下:
msvc9compiler.py中
修改MSVCCompiler函数:
vc_env = query_vcvarsall(VERSION, plat_spec)
为:
如果安装的是VS2014,则VERSION为13.0;
如果安装的是VS2013,则VERSION为12.0;
如果安装的是VS2012,则VERSION为11.0;
如果安装的是VS2010,则VERSION为10.0;
如果安装的是VS2008,则VERSION为9.0。
像我的安装的是VS2013,则
vc_env = query_vcvarsall(12.0, plat_spec)

在我的电脑上,我查过它查找的VERSION为10.0,也就是VS2010,所以要人工干预下,而且修改此处对整个程序没有影响,除非你换了VS版本

至于题主为啥2008版的没用,因为Python3.4默认2010版,你也可以直接下2010的,这就不用改了 泻药,以下回答不保证是正确的。

1 直接下载预编译好的二进制安装包。

2 那个玩意是vc里的,我记得这里有个vc版本问题,这个文件名好像不一样,你进去安装包里,看看实际用的是哪个脚本,找不到可能要添加环境变量。提示:这个是可以配置成使用mingw的,也是安装脚本setup.py里配置的,如果你最后没搞定,可以尝试改成使用mingw。

3 换linux 使用系统带的包管理器装,通常问题不大。 直接按 @cloak shining给的链接下二进制包就行。

python在windows下通过pip安装带有c扩展的包时,如果是python 2.7,需要vs2008,如果是python 3.x,需要vs2010,版本错了都不行,更别提mingw。因为c运行时不兼容的原因。

还有两个一劳永逸的解决方案:
1. 换linux
2. 用Anaconda Scientific Python Distribution

产生原因:

python3.4用的是msvs2010编译的,所以python3.4默认只能认出msvs2010。

python2.7用的是msvs2008编译的,所以python2.7默认只能认出msvs2008.

方法一:安装mingw(不推荐)

下载mingw环境,添加环境变量

或者使用

python setup.py build –compiler=mingw32
感谢@许仙的回答,我这里补充一下,安装whl文件需要使用cmd进入python/Scripts/。然后运行 pip3.4 install xxxxx.whl(针对3.4版本) 今天花了一天的时间解决这个问题!基本把网上说的方法都试了,什么注册表,改keytool,装了vs2010等等,最后是看python源代码解决的。

我的python版本是Python 3.5

该问题的产生是在windows环境中,python 的 Setup需要调用一个vcvarsall.bat的文件,该文件需要安装c++编程环境才会有。网上的方法有两个:一、安装MinGW;二、安装Visual Studio 。我用的是第二种方法。

步骤一:

在你的python程序所在文件夹中找到:“_msvccompiler.py”文件,例如我的电脑中的路劲是:

D:\Program Files\Anaconda3\Lib\distutils\_msvccompiler.py

找到后用编辑器打开,找到“_find_vcvarsall”函数声明中类似“if version >= 14 and version > best_version:”注意这里的“14”,如果这里是14说明VS版本要在14以上才可以。所以根据这句,我们要安装最新的Visual Studio2015。(相对的如果是9就是9以上即可这时VS10什么都是可以的)


步骤二:

现在Visual Studio 2015有社区版,可以免费使用,这个版本就够了。为了方便大家,我放在云盘。你也可以去官网下载。

http://pan.baidu.com/s/1eSueWLG


下载完毕后进行安装:

注意一定要勾选c++环境,和XXXfor python,这两个。web development应该是没有影响的,但是由于这是软件默认勾选的,所以我也装了。

这一步,出现了一直停留在“Configuring Your System”的问题,然后在网上找到了如下解决方案:(Visual Studio Express 2013 for windows with update 2 installation Taking Too much time in "Configuring Your System")

意思就是把VS的进程都关了。我关掉VS2015后分分钟就好了

Python3.4 用 pip 安装lxml时出现 “Unable to find vcvarsall.bat ”? 微软社区的开放者对这个问题给出了答复。一句话:对于python,3.4 安装Windows SDK for Windows 7 and .NET 4.0(或者 Visual Studio 2010) 。对其他版本,见表:
Python3.4 用 pip 安装lxml时出现 “Unable to find vcvarsall.bat ”?
引自 https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/ 额, 如果有人还看到这里,那你试一下这样:
按照 深海鱼 的方法下载到whl文件,然后重命名为zip,解压后放到python安装目录下的lib中。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Python vs. C  : Understanding the Key DifferencesPython vs. C : Understanding the Key DifferencesApr 21, 2025 am 12:18 AM

Python and C each have their own advantages, and the choice should be based on project requirements. 1) Python is suitable for rapid development and data processing due to its concise syntax and dynamic typing. 2)C is suitable for high performance and system programming due to its static typing and manual memory management.

Python vs. C  : Which Language to Choose for Your Project?Python vs. C : Which Language to Choose for Your Project?Apr 21, 2025 am 12:17 AM

Choosing Python or C depends on project requirements: 1) If you need rapid development, data processing and prototype design, choose Python; 2) If you need high performance, low latency and close hardware control, choose C.

Reaching Your Python Goals: The Power of 2 Hours DailyReaching Your Python Goals: The Power of 2 Hours DailyApr 20, 2025 am 12:21 AM

By investing 2 hours of Python learning every day, you can effectively improve your programming skills. 1. Learn new knowledge: read documents or watch tutorials. 2. Practice: Write code and complete exercises. 3. Review: Consolidate the content you have learned. 4. Project practice: Apply what you have learned in actual projects. Such a structured learning plan can help you systematically master Python and achieve career goals.

Maximizing 2 Hours: Effective Python Learning StrategiesMaximizing 2 Hours: Effective Python Learning StrategiesApr 20, 2025 am 12:20 AM

Methods to learn Python efficiently within two hours include: 1. Review the basic knowledge and ensure that you are familiar with Python installation and basic syntax; 2. Understand the core concepts of Python, such as variables, lists, functions, etc.; 3. Master basic and advanced usage by using examples; 4. Learn common errors and debugging techniques; 5. Apply performance optimization and best practices, such as using list comprehensions and following the PEP8 style guide.

Choosing Between Python and C  : The Right Language for YouChoosing Between Python and C : The Right Language for YouApr 20, 2025 am 12:20 AM

Python is suitable for beginners and data science, and C is suitable for system programming and game development. 1. Python is simple and easy to use, suitable for data science and web development. 2.C provides high performance and control, suitable for game development and system programming. The choice should be based on project needs and personal interests.

Python vs. C  : A Comparative Analysis of Programming LanguagesPython vs. C : A Comparative Analysis of Programming LanguagesApr 20, 2025 am 12:14 AM

Python is more suitable for data science and rapid development, while C is more suitable for high performance and system programming. 1. Python syntax is concise and easy to learn, suitable for data processing and scientific computing. 2.C has complex syntax but excellent performance and is often used in game development and system programming.

2 Hours a Day: The Potential of Python Learning2 Hours a Day: The Potential of Python LearningApr 20, 2025 am 12:14 AM

It is feasible to invest two hours a day to learn Python. 1. Learn new knowledge: Learn new concepts in one hour, such as lists and dictionaries. 2. Practice and exercises: Use one hour to perform programming exercises, such as writing small programs. Through reasonable planning and perseverance, you can master the core concepts of Python in a short time.

Python vs. C  : Learning Curves and Ease of UsePython vs. C : Learning Curves and Ease of UseApr 19, 2025 am 12:20 AM

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools