1

I am trying to compile some C code using a setup.py file like so:

from distutils.core import setup, Extension

module1 = Extension('myc',
                    sources = ['myc.c'])

setup (name = 'myc',
       version = '1.0',
       description = 'This is a demo package',
       ext_modules = [module1])

And then entering python setup.py build_ext --inplace --compiler=msvc into a powershell window in the same folder as the setup.py file. But it encounters an error:

error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.11.25503\\bin\\HostX86\\x64\\link.exe' failed with exit status 1120

I have downloaded visual C++ 2015 on visual studio community 2017 because I read that I needed the same VC compiler that was used for my python version. However it seems as though it's still trying to use the 2017 compiler, I think?

Please note I have two versions of Python installed, 3.44 and 3.63 and I want to compile using 3.63.

Checking that python accesses 3.63 in the powershell window:

Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32

This was marked as a duplicate of Linking errors when compiling python extension module but the answer there is simply to "install the correct version of VC++ for your python installation" and I have done that

The issue seems to be how to change which msvc version to use. I am also curious if setuptools would make a difference but I do not have knowledge of its functions

As a side note aimed at Python, if this was easy; everyone, including amateurs like me, would be improving bottleneck parts of their code by writing it in C. Many businesses would potentially get better results from their Python code

ragardner
  • 1,836
  • 5
  • 22
  • 45

0 Answers0