Suppose that you want to run a Python script or command via a Shell script (.sh
) using a specific conda environment. Let’s see how we can do it. First of all, you need to find the path of your conda environment which can be retrieved by running the command:
conda env list
Assume that our conda environment is the ‘gpipis‘ and the path is the “/home/ds/.conda/envs/gpipis“. Finally, let’s assume that our python script is the “my_python.py“. Let’s see how we can run the shell script asking to run the python script from the “gpipis” conda environment.
You will need to specify the whole path of your shell script. So, the “my_shell.sh” can be:
#!/bin/bash /home/ds/.conda/envs/gpipis/bin/python /script_path/my_python.py
And you can run it as:
./my_shell.sh