This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Error when building Python extension
Type: compile error Stage: resolved
Components: Distutils Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Mark53, dstufft, eric.araujo, zach.ware
Priority: normal Keywords:

Created on 2016-06-15 09:12 by Mark53, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg268612 - (view) Author: Mark (Mark53) Date: 2016-06-15 09:12
I'd like to build a C++ extension for Python. I took a simple C file from a tutorial and wrote the setup.py file. But when I run the command:
python setup.py build_ext --inplace

I get the following error:
error: Unable to find vcvarsall.bat

This file is located in "c:\Program Files (x86)\Microsoft Visual Studio 12.0\vc\vcvarsall.bat" but even when I run it and set all environment variables, python.exe still tries to find it. I added this path to the PATH but it didn't solve the issue.
msg268619 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2016-06-15 13:42
Hi Mark,

To build Python extensions on Windows, you need to have a compiler that can link to the same C runtime used by the Python interpreter. For 3.5, that means you need VS2015; VS2013 won't work.
msg268621 - (view) Author: Mark (Mark53) Date: 2016-06-15 16:39
Hi Zach,

Well, the strange thing is that other members of my team have successfully built C++ Python extensions with Visual Studio 13, but they compiled and built the pyd file with CMake (one used SWIG). So, it is possible. I just wanted to do it in a simpler way.

Regards,

Mark

---- Message d'origine ----
De : Zachary Ware <report@bugs.python.org>
À : tibo53@netcourrier.com
Objet : [issue27324] Error when building Python extension
Date : 15/06/2016 15:42:36 CEST

Zachary Ware added the comment:

Hi Mark,

To build Python extensions on Windows, you need to have a compiler that can link to the same C runtime used by the Python interpreter. For 3.5, that means you need VS2015; VS2013 won't work.

----------
nosy: +zach.ware
resolution: -> not a bug
stage: -> resolved
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue27324>
_______________________________________
msg268622 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2016-06-15 16:54
Using the wrong compiler, you may wind up with an extension that appears to work, and you may never have a problem with it if conditions are just right.  This article[1] looks like a pretty good explanation of why you don't want to do it, though (note: I've only skimmed the article).

If you really want to shoot yourself in the foot, you can try running vcvarsall.bat yourself, then make sure MSsdk is set (distutils doesn't care what it's set to, just that it's set), and set DISTUTILS_USE_SDK (again, doesn't matter to what).

Also, note that this problem should be a thing of the past with Python 3.5+ and VS2015+.

[1] http://siomsystems.com/mixing-visual-studio-versions/
msg268650 - (view) Author: Mark (Mark53) Date: 2016-06-16 08:38
The problem is that I don't have the choice, the compiler we use for the project is VS13. Anyway, my colleagues are aware of this limitation but they could build their extensions all the same.

I set the variables as you recommended, and the obj files have been created. But the link fails with the following error:

LINK : fatal error LNK1181: impossible to open the input file 'ucrt.lib'

This library does not exist in my VS13 environment.

---- Message d'origine ----
De : Zachary Ware <report@bugs.python.org>
À : tibo53@netcourrier.com
Objet : [issue27324] Error when building Python extension
Date : 15/06/2016 18:54:39 CEST

Zachary Ware added the comment:

Using the wrong compiler, you may wind up with an extension that appears to work, and you may never have a problem with it if conditions are just right. This article[1] looks like a pretty good explanation of why you don't want to do it, though (note: I've only skimmed the article).

If you really want to shoot yourself in the foot, you can try running vcvarsall.bat yourself, then make sure MSsdk is set (distutils doesn't care what it's set to, just that it's set), and set DISTUTILS_USE_SDK (again, doesn't matter to what).

Also, note that this problem should be a thing of the past with Python 3.5+ and VS2015+.

[1] http://siomsystems.com/mixing-visual-studio-versions/

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue27324>
_______________________________________
History
Date User Action Args
2022-04-11 14:58:32adminsetgithub: 71511
2016-06-16 08:38:46Mark53setmessages: + msg268650
2016-06-15 16:54:39zach.waresetmessages: + msg268622
2016-06-15 16:39:29Mark53setmessages: + msg268621
2016-06-15 13:42:36zach.waresetstatus: open -> closed

nosy: + zach.ware
messages: + msg268619

resolution: not a bug
stage: resolved
2016-06-15 09:12:47Mark53create