Skip to content Skip to sidebar Skip to footer

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(

Solution 1:

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.

Solution 2:

run the other file via the following command.

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

Post a Comment for "How To Call Anaconda Environment To Run Specific Package Of Python(2.7) From Other Python(3.7) Script Via Os.system()?"