2

So I have a python script that generates an animation - and it requires libraries that I have in a conda environment. I need to run this script as soon as my computer turns on, so I've written a short bash script that I added to "startup applications". This bash script runs on startup, and reads like this:

#!/bin/bash

conda activate myenv
cd ~/scripts
python generate.py

When I run this in terminal myself, it's fine, but whenever I turn on the computer, the python part of the script doesn't execute, and when I check errors i find:

conda: command not found

and then i also see the python script failed to run because it's missing libraries (from the conda environment not activating)

I have tried adding lines to the bash script replacing "conda activate" with "source activate", I have tried adding echo ". /home/<user>/anaconda3/etc/profile.d/conda.sh" >> ~/.bashrc to the bash script, replacing "conda" with /home/barrat/anaconda3/bin/conda, and even adding whoami to the bash script that runs at startup to make sure that i haven't magically become root by chance... none of this has worked. I would really appreciate any help. it's 3 AM and i'm a bit desperate.

2

I would comment but I don't have enough reputation so instead I am writing my guess here as an answer.

conda init added the following lines to the very end of my .bashrc

# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/home/<user>/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/<user>/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/<user>/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        export PATH="/home/<user>/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

I am not sure what exactly it does but one way or another it seems to add conda to the path. (Also it properly configures your shell to use conda activate, apparently)

If your script gets run before conda gets "initialized" by those lines, perhaps your bash does not know what conda is at that time. So complains conda: command not found

You could try running these lines before your script and see if it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.