Force compiler when running python setup.py install

前端 未结 4 1786
后悔当初
后悔当初 2021-02-04 00:40

Is there a way to explicitly force the compiler for building Cython extensions when running python setup.py install? Where setup.py is of the form:

4条回答
  •  孤独总比滥情好
    2021-02-04 01:14

    I ended up putting this at the beginning of setup.py to force visual2015

    useful when running in a non bat environment and starting vcvarsall from outside is not an option

    if sys.platform == 'win32':
        # patch env with vcvarsall.bat from vs2015 (vc14)
        try:
            cmd = '"{}..\\..\\VC\\vcvarsall.bat" x86_amd64 >nul 2>&1 && set'.format(environ['VS140COMNTOOLS'])
            out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, universal_newlines=True)
        except:
            print("Error executing {}".format(cmd))
            raise
    
        for key, _, value in (line.partition('=') for line in out.splitlines()):
            if key and value:
                os.environ[key] = value
    
        # inform setuptools that the env is already set
        os.environ['DISTUTILS_USE_SDK'] = '1'
    

提交回复
热议问题