I have two directory of same level. For example - Folder A and Folder B. Folder A use python3.7 and Folder B have anaconda environment which use python2.7. I run os.system("python ../folder b/ex2.py").
In folder B the anaconda environment is activated.
The problem is when I run from terminal , the python script(python ../folder b/ex2.py) run successfully but when I call the script from folder A script, it doesn't use anaconda environment.
解決方案
Assuming your conda env is name python2.7. Change
os.system('python ../folderb/ex2.py')
to
os.system('conda activate python2.7 && python ../folderb/ex2.py')
This should execute your ex2.py within the conda env.