This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Import Bio module from Bash

I'm working on a remote server with Linux. I created a new environment and got biopython installed with conda:

conda create --name new_bio python=3.5
conda activate new_bio
conda install -c conda-forge biopython

import Bio works when I am running it inside python:

(new_bio) -bash-4.2$ python
Python 3.5.5 | packaged by conda-forge | (default, Jul 23 2018, 23:45:43)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import Bio
>>> exit()

import Bio works when I am running my script like this:

(new_bio) -bash-4.2$ python my_Bio_script.py
hello

my_Bio_script.py:

from Bio import SeqIO
print('hello')

But when I try to run my script with Bash :

(new_bio) -bash-4.2$ sbash my_bash.sh 

my_bash.sh bash file:

#!/bin/bash
module load anaconda           ### load anaconda module
source activate new_bio        ### activating environment, environment 
must be configured before running the job


python my_Bio_script.py

I get this error:

Traceback (most recent call last):
File "T.py", line 1, in <module>
from Bio import SeqIO
ModuleNotFoundError: No module named 'Bio'

I have to send it as a Slurm Job in a bash file.. what can I do?

bash biopython slurm

1 answer

Your conda environment is not activating properly when you start a new bash shell

see the following recent post for solutions

Why piping a conda command into bash doesn't work ?

Log in to answer this question.