Using conda install within a python script

前端 未结 6 1909
后悔当初
后悔当初 2021-02-04 02:13

According to this answer you can import pip from within a Python script and use it to install a module. Is it possible to do this with conda install?

The co

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 02:45

    I know this question is quit old but I found that conda.cli.python_api and conda.api have are limited in the sense that they both don't have the option to execute commands like this:

    conda export env > requirements.txt

    So instead I used subprocess with the flag shell=True to get the job done. subprocess.run(f"conda env export --name {env} > {file_path_from_history}",shell=True) where env is the name of the env to be saved to requirements.txt.

    Hope this helps someone.

提交回复
热议问题