如何在Python脚本中将PATH =%PATH%设置为环境? [英] how to set PATH=%PATH% as environment in Python script?

查看:377
本文介绍了如何在Python脚本中将PATH =%PATH%设置为环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从python程序启动exe文件(该exe文件是用Visual Studio编译的c ++项目的输出).在此c ++项目的属性(配置-> properties->调试->环境)中,

I'am trying to start an exe file (the exe file is the output of c++ project compiled with visual studio) from a python program. In the properties of this c++ project (configuration ->properties-> debugging-> environment) the following setting in the

     (PATH = %PATH%;lib\testfolder1;lib\testfolder2) 

给出

.
有什么方法可以将路径环境变量设置为

is given.
is there any way to set path environment variable to

  1. PATH =%PATH%
  2. lib \ testfolder1
  3. lib \ testfolder2

在python程序中?

in a python program?

预先感谢您的重播

推荐答案

您可以使用以下几种方法来更新PATH:

You can update PATH using several methods:

import sys
sys.path += ["c:\\new\\path"]
print sys.path

import os
os.environ["PATH"] += os.pathsep + os.pathsep.join(["c:\\new\\path"])
print os.environ["PATH"]

这篇关于如何在Python脚本中将PATH =%PATH%设置为环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆