Compiled Python extension library encountered "Unable to find Vcvarsall.bat" workaround

Source: Internet
Author: User

Recently wanted to learn about Python's Paramiko library, Paramiko relies on Pycrypto, when compiling Pycrypto encountered a problem, the general meaning is:

 
   
  
  1. unable to find vcvarsall.bat
Problem Analysis:

Follow the error message and navigate to the following file

 
   
  
  1. python_path/lib/distutils/msvc9compiler.py

Simple analysis of the source code, found that when compiling the extension library, the function provided in this file to determine the path of Vcvarsall.bat to set the VC environment variables,
A global variable is defined in the msvc9compiler.py

 
   
  
  1. VERSION = get_build_version()

Use the Get_build_version () function to get the version number of the VC, and this version is actually compiled Python is the VC version, probably because most people's python is not compiled by themselves, resulting in the version of the VC obtained through this function is not accurate.

In msvc9compiler.py, a class msvccompiler is defined:

 
   
  
  1. class MSVCCompiler(CCompiler) :
  2. """Concrete class that implements an interface to Microsoft Visual C++,
  3. as defined by the CCompiler abstract class."""

The VC environment variable is set in the initialization function initialize of the Msvccompiler class, that is, the path of the Vcvarsall.bat is obtained through a series of functions:

  
 
  1. #初始化函数initialize首先调用query_vcvarsall
  2. vc_env = query_vcvarsall(VERSION, plat_spec) #VERSION为上面提到的全局变量
  3. #vc_env调用find_vcvarsall
  4. vcvarsall = find_vcvarsall(version) #find_vcvarsall查找vcvarsall.bat的路径,参数version=VERSION

If the value of version does not match the version of the VC that is installed natively, you will not find the Vcvarsall.bat.

Workaround:

Modify Code

 
   
  
  1. VERSION = get_build_version()

For

 
   
  
  1. VERSION = 10.0 #10.0为VC的版本号

The specific version number differs according to the actual installation of Visual Studio, VS2010 is 10.0.



From for notes (Wiz)

Compiled Python extension library encountered "Unable to find Vcvarsall.bat" workaround

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.