Python - Activate conda env through shell script

前端 未结 6 974
遥遥无期
遥遥无期 2020-11-30 03:14

I am hoping to run a simple shell script to ease the management around some conda environments. Activating conda environments via conda activate in a lin

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 04:02

    I also had the exact same error when trying to activate conda env from C++ or Python file. I solved it by bypassing the conda activate statement and using the absolute path of the specific conda env.

    For me, I set up an environment called "testenv" using conda.

    I searched all python environments using

    whereis python | grep 'miniconda'
    

    It returned a list of python environments. Then I ran my_python_file.py using the following command.

    ~/miniconda3/envs/testenv/bin/python3.8 my_python_file.py
    

    You can do the same thing on windows too but looking up for python and conda python environments is a bit different.

提交回复
热议问题