Win7 64-bit compilation Python extension solves the "error:unable to find Vcvarsall.bat" problem __python

Source: Internet
Author: User
Tags windows 7 x64 visual studio 2010

After testing, this method is suitable for installing vcforpython27.msi but reporting the same error.


The following are reproduced:

Prior to using the WIN32 system, visual Studio 2010 and the corresponding SDK were installed on the system, and then python compiled the extension command Python setup.py install but the command always failed, appearing error:unable to find Vcvarsall.bat, such as compiling Py-bcrypt extensions:

Running install
running Bdist_egg
running Egg_info
writing py_bcrypt.egg-info\pkg-info
writing Top-level names to Py_bcrypt.egg-info\top_level.txt
writing dependency_links to Py_bcrypt.egg-info\dependency_ Links.txt
reading manifest file ' py_bcrypt.egg-info\sources.txt ' writing
manifest file ' py_bcrypt.egg-info\ SOURCES.txt '
Installing library code to Build\bdist.win-amd64\egg
running Install_lib
running
running Build_ext
building ' bcrypt._bcrypt ' extension error:unable to find
Vcvarsall.bat

Search for most of the online solutions, mostly to you to change the MINGW32 or modify the official Python source code, the use of mingw32 will appear like undefined reference to ' _imp__py ... ' build\ temp.win-amd64-2.7 was unable to link to the Python library, and was trying to find a solution to this, resulting in a text found on StackOverflow "Cython won ' t compile on Windows 7 x64." Poured me a pot of cold water:

I ' d suggest you to switch to x86 Python and you gain no real advantage by using the x64 version. If you are want to stick with x64, you can ' t use MinGW and your have to use MS SDK C + + compiler.

It means that you can't compile a 64-bit Python extension using MinGW, and if you do that you have to use msvc Microsoft's compiler, and some people are sure to ask why not use 64-bit mingw64. The original author also gives the explanation, also can refer to "compiling 64-bit extension modules on Windows" this article:

* * Don't use MINGW-W64. As you'll notice, the MinGW import library for Python (e.g. libpython27.a) are omitted from the AMD64 version of Python. This is deliberate. Do don't try to make one using Dlltool. There is no official MINGW-W64 release yet, it are still in "beta" and considered unstable, although your can get a 64-bit b Uild from e.g. TDM-GCC. There have also been issues with the MinGW runtime with the conflicting MSVC; This can happen from places to don ' t expect, such as inside runtime for libraries or g++. To stay on the safe side and avoid mingw-w64 for now.

Mingw64 is not stable, there are some problems, then the problem is back to the beginning, there is a way to change the official installation script source code, I think this is not very good, so groping for some, just again in StackOverflow found such an article "Building 64- Bit C Python extensions on Windows, and then the problem was solved successfully.

I'll share the following steps to compile the operation:

1. Open the 64-bit Visual Studio 2010 command-line compilation mode, which you can then –microsoft Visual Studio 2010–visual Studio Tools–visual Studio x64 from the Start menu Win64 Command Prompt (2010), as shown in the following illustration:

2. Use the following command to set up the environment:

Set Distutils_use_sdk=1
Set mssdk=1

2. Switch to the path where you want to compile the extension setup.py run the following command to compile:

Python setup.py Install

After a while, if the dependent dependencies are not wrong, and the source code is correct, it should be able to compile successfully. Once the compilation is complete, you can find the code package from the Build\lib.win-amd64-2.7\, and it is already installed into the Python environment.

If there is a problem with the compilation, such as a link failure, you can check if there is a problem with the environment settings, such as whether the system path variable contains C:\Python27\libs and the Python is installed in the C disk.

Note: The above scenarios are passed in Windows 7 x64, Visual Studio 2010, and Python x64 tests.

Related Article

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.