I am trying to run the vcvarsall.bat bat script to initialize all the environment variables so that I can run follow up commands, but it does not seem to be working the way I'd like it to. Here's a snippet of my code:
try:
path = r'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat'
subprocess.Popen([vcvars, 'x64'], shell=True)
except FileNotFoundError:
print("Visual Studio is not installed on this system")
I also print the PATH variable after, but it does not seem to stick after running this function here. Is this even possible?
CodePudding user response:
You're creating a development environment when you execute vcvarsall.bat
, but once the child process is terminated, the created environment is destroyed. In no way environment modifications done by a child process would be brought back in parent's environment - that's normal, on purpose, and a LOT of things would break instantly in most operating systems if it wasn't the case.
You should call this batch BEFORE running Python and your program, so all required variables will be already in environment.