1

Info:

Python Version : 3.7.4

Platform : win 10 64 bit


I am trying to compile the file compileModule.py using command :

python compileModule.py build_ext --inplace 

compileModule.py:

from distutils.core import setup, Extension
from distutils.sysconfig import *
from distutils.util import *
from Cython.Distutils import build_ext
import numpy
import os
import os.path

try:
   from distutils.command.build_py import build_py_2to3 \
       as build_py
except ImportError:
   from distutils.command.build_py import build_py

try:
   from Cython.Distutils import build_ext
except ImportError:
   use_cython = False
else:
   use_cython = True


py_inc = [get_python_inc()]

np_lib = os.path.dirname(numpy.__file__)
np_inc = [os.path.join(np_lib, 'core/include')]
ext_inc = os

sourcefiles = ["utilFunctions.c", "cutilFunctions.pyx"]

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("utilFunctions_C",sourcefiles, libraries=['m'], include_dirs=py_inc + np_inc)]
  )

After executing the above command I got an error :

 Unable to find vcvarsall.bat

I downloaded and installed the Build Tools for Visual Studio 2017 by following the solution on this post.

Then i execute the below command again :

python compileModule.py build_ext --inplace 

which gives a new error:

LINK : fatal error LNK1181: cannot open input file 'm.lib'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.22.27905\\bin\\HostX86\\x64\\link.exe' failed with exit status 1181

Now I am stuck with this error. Does anyone have any idea how to solve this error?

P.S. I opened all cmd inside Vs code but still same error :

enter image description here

Anudocs
  • 686
  • 1
  • 13
  • 54
  • Have you tried opening the command prompt from the entry MSBuild created when you installed it (somewhere in the start menu, but not the plain Command Prompt entry)? If not, please try that first. I believe it sets all kinds of environment variables and paths that may be required. – blubberdiblub Sep 16 '19 at 11:19
  • The linker cannot find your standard math library. This should be in the folder that your toolchain is installed, possibly in `C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.22.27905\\lib`(wild guess). Try to find the path where your standard libraries are and add it to your `include_dirs`. – th33lf Sep 16 '19 at 11:23
  • @blubberdiblub : I see 4-5 command prompts(screenshot updated in the question). I opened all of them but no success – Anudocs Sep 16 '19 at 11:28
  • @th33lf: Please explain your comment. I found 3 folders in the path you mentioned: 'onecore', 'x64', 'x86' – Anudocs Sep 16 '19 at 11:33
  • @AnubhavJhalani Looks like you are building for x64, so look in that folder. Inside that folder (or one of its subfolders) should be the library that you are missing. Add this path to your includes and all should be well. – th33lf Sep 16 '19 at 12:14
  • @th33lf: i dont find m.lib in any of the folder. – Anudocs Sep 16 '19 at 12:35
  • 1
    @AnubhavJhalani Try buildling without the `libraries=['m']` line then – th33lf Sep 16 '19 at 12:42
  • I did and it got executed without error – Anudocs Sep 16 '19 at 12:45
  • @AnubhavJhalani Since you solved the error yourself, it would perhaps be nice to write it down as an answer as well, for future reference. – th33lf Sep 16 '19 at 13:33

1 Answers1

1

I found following solution to my problem:

I deleted libraries=['m'] from the compileModule.py and then file got compiled without any error.

Anudocs
  • 686
  • 1
  • 13
  • 54