Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set PATH=%PATH% as environment in Python script?

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

in a python program?

Thanks in advance for your replay

like image 416
sasi Avatar asked Feb 08 '23 07:02

sasi


2 Answers

You can update PATH using several methods:

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

or

import os
os.environ["PATH"] += os.pathsep + os.pathsep.join(["c:\\new\\path"])
print os.environ["PATH"]
like image 69
Yaron Avatar answered Feb 11 '23 21:02

Yaron


Repost Yaron's answer but dropped the sys.path. As in his post's comment, sys.path is for module search, not command search. PATH is for command search.

import os
os.environ["PATH"] += os.pathsep + os.pathsep.join(["c:\\new\\path"])
print os.environ["PATH"]
like image 27
oldpride Avatar answered Feb 11 '23 21:02

oldpride