calling conda source activate from bash script

后端 未结 3 1798
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 07:25

I\'m trying to activate my conda env via a bash script. Even though the script runs fine and my PATH appears to be changed within the script, it\'s getting reset somehow aft

相关标签:
3条回答
  • 2020-12-09 07:58

    I have found the following to work on Mac OSX running a bash shell:

    #!/bin/bash
    source /Users/yourname/anaconda/bin/activate your_env
    python --version # example way to see that your virtual env loaded as expected
    

    Make sure you make the scripted executable with:

    chmod +x yourscript.bash
    
    0 讨论(0)
  • 2020-12-09 08:12

    See the link below,

    digitalocean-how-to-read-and-set-environmental-and-shell-variables-on-a-linux-vps

    below is the snippet from the website,

    This is because environmental variables are only passed to child processes. There isn't a built-in way of setting environmental variables of the parent shell. This is good in most cases and prevents programs from affecting the operating environment from which they were called.

    0 讨论(0)
  • 2020-12-09 08:22

    On more recent versions of conda (4.6+), I have noticed that the following works:

    eval "$(conda shell.bash hook)"
    conda activate <env-name>
    
    0 讨论(0)
提交回复
热议问题