如何设置vsvars32环境变量?
我正在努力为 Visual Studio 2008 设置 scons 环境变量。
通常我会执行以下操作:
%VS90COMNTOOLS%vsvars32.bat
or
call %VS90COMNTOOLS%vsvars32.bat
这在我的 shell 中有效。
我尝试使用子进程
subprocess.call([os.environ['VS90COMNTOOLS']+r"\vsvars32.bat"])
输出在 python 中执行此操作:
d:\N\workspace>scons test
scons: Reading SConscript files ...
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
KeyError: 'INCLUDE':
上面调用批处理,但环境变量不会从它继承到我的“主进程”。
当我使用:
subprocess.call([os.environ['VS90COMNTOOLS']+r"\vsvars32.bat"])
我得到:
d:\N\workspace>scons test
scons: Reading SConscript files ...
WindowsError: [Error 2] The system cannot find the file specified:
File "D:\N\workspace\SConstruct", line 17:
subprocess.Popen(["call ", os.environ['VS90COMNTOOLS']+r"\vsvars32.bat"])
File "C:\Python26\lib\subprocess.py", line 595:
errread, errwrite)
File "C:\Python26\lib\subprocess.py", line 821:
startupinfo)
如何实现这一点?
I'm struggling with setting my scons environment variables for visual studio 2008.
Normally I do following:
%VS90COMNTOOLS%vsvars32.bat
or
call %VS90COMNTOOLS%vsvars32.bat
And this works in my shell.
I try to do that in python using subprocess
subprocess.call([os.environ['VS90COMNTOOLS']+r"\vsvars32.bat"])
output:
d:\N\workspace>scons test
scons: Reading SConscript files ...
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
KeyError: 'INCLUDE':
above invokes batch process, but environment variables are not inherited from it to my 'master process.
When i use:
subprocess.call([os.environ['VS90COMNTOOLS']+r"\vsvars32.bat"])
I get:
d:\N\workspace>scons test
scons: Reading SConscript files ...
WindowsError: [Error 2] The system cannot find the file specified:
File "D:\N\workspace\SConstruct", line 17:
subprocess.Popen(["call ", os.environ['VS90COMNTOOLS']+r"\vsvars32.bat"])
File "C:\Python26\lib\subprocess.py", line 595:
errread, errwrite)
File "C:\Python26\lib\subprocess.py", line 821:
startupinfo)
How to achieve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编写一个运行
vsvars32.bat
的批处理文件,然后以VARNAME=value
形式输出值,然后让 Python 脚本解析这些值并将它们注入os.environ
。这是在 python 自己的 distutils 模块中完成的,在此处查看源代码。
Write a batch file that runs
vsvars32.bat
and then outputs the values in the formVARNAME=value
, then have your Python script parse the values and inject them intoos.environ
.This is done in python's own distutils module, see the source here.
除了之前的回答。我的 SConstruct 摘录:
请注意 Python 中的变量名称区分大小写。确保您的
env['ENV']
字典没有大小写不同的重复变量名称,否则 Windows shell 只会看到该变量的一种变体。In addition to the previous answer. An excerpt of my SConstruct:
Please take care that variable names in Python are case-sensitive. Ensure that your
env['ENV']
dict has no duplicate variable names with different case, otherwise the Windows shell will only see one variant of the variable.对已接受答案的简短代码(Python 3)补充:
它对我有用!
A short code (Python 3) addition to the accepted answer:
It works for me!