简体   繁体   中英

How to call anaconda environment to run specific package of python(2.7) from other python(3.7) script via os.system()?

I have two directories at the same level. For example Folder A and Folder B. Folder A uses python3.7 and Folder B has an Anaconda environment which uses 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 the python script from Terminal python ../folder b/ex2.py it runs successfully but when I call the script from folder A it doesn't use the 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.

通过以下命令运行另一个文件。

os.system('conda run -n <env_name> python <path_to_other_script>')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM