c调用python环境_如何使用由设置的环境从python脚本调用CMakevcvarsall.bat?

我很幸运找到了自己问题的答案。在

下面是要使用的正确python调用:src_dir = ... # set your source dir here

build_dir = ... # set your build dir here

# retrieve visual studio installation path using vswhere.

# See: https://github.com/Microsoft/vswhere

vswhere = os.path.join(os.environ['ProgramFiles(x86)'],

"Microsoft Visual Studio",

"Installer",

"vswhere.exe")

# get installation path of Visual Studio 2017

vspath = subprocess.Popen([vswhere, "-property", "installationPath", "-version", "[15,16)"],

stdout=subprocess.PIPE).communicate()[0].rstrip()

# build path to vcvarsall.bat file

vcvarsall = os.path.join(vspath, "VC", "Auxiliary", "Build", "vcvarsall.bat")

# vcvarsall.bat changes the current directory to the one specified

# by the environment variable %VSCMD_START_DIR%

my_env = os.environ

my_env["VSCMD_START_DIR"] = build_dir

# set up the environment and then call cmake with Ninja generator

subprocess.call('call "' + vcvarsall + '" x64 && cmake -G Ninja "' + src_dir + '"', shell=True, env=my_env)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值