python – How to fix ‘sh: conda: command not found’ error when creating a YML environment in Anaconda3?

creating yml environment but getting sh: conda: command not found. Even after doing below still same error. export/usr/local/anaconda2/bin:$PATH

import os

# Create the environment.yml file
env_yaml=""'
name: myenv
channels:
  - conda-forge
dependencies:
  - r-base=4.2.2
  - r-methods
  - r-rvest
  - r-dplyr
  - r-readr
'''

with open('environment.yml', 'w') as file:
    file.write(env_yaml)

os.system('conda env create -f environment.yml')
os.system('conda activate myenv')

Read more here: Source link