-2

When I import Bio in a Jupyter notebook in Anaconda on a Mac I this error: No module named 'Bio'.

Reto
  • 1
  • 1
  • Is biopython set up correctly? Is the notebook using the right Python installation/Conda environment? – AMC Oct 08 '20 at 21:51

1 Answers1

0

Somehow the import settings weirdly case sensitive. This will fix it:

# Installing the biopython libraries in this runtime environment
!pip3 install biopython==1.78
# The next two lines fix the error "No module named 'Bio'"
# that occurs with an Anaconda Navigator installation on OSX
# by making python imports case insensitive
import os
os.environ['PYTHONCASEOK'] = '1'

# On to regularly scheduled imports.
import Bio

Further experiments show that other permutations won't work in both google colab and Jupyter; and I am not sure why:

I have run some experiments with this and after uninstalling all bio and biopython variants (just to be sure, they were not actually installed), I fount that

!pip3 install bio
import bio

works on anaconda but not on google colab. If I import Bio with a capital B it works on neither of them.

!pip3 install bio
import os
os.environ['PYTHONCASEOK'] = '1'
import Bio
print("All's well")

works on Jupyter but errors out "ModuleNotFoundError: No module named 'Bio'" on collab. Import lower case bio behaves the same.

# Solution that works on both colab.google.com and 
# Anaconda Navigator Jupyter notebooks
!pip3 install biopython
import os
os.environ['PYTHONCASEOK'] = '1'
import Bio

works for Anaconda Jupyter and Google Colab. If you change the case to 'import bio' it stops working on Google.

Reto
  • 1
  • 1
  • I guess at some point you ran `pip install bio` instead of `pip install biopython`- this leads to issues see https://github.com/biopython/biopython/issues/2363 I suggest you re-install – Chris_Rands Oct 09 '20 at 10:08
  • Thanks @Chris_Rands, I've tried that and documented the outcome in the answer. Short answer, it does not work like that in notebooks it seems. If you have anthing else to try let me know. There is a solution but it's a bit unusual,,, – Reto Oct 10 '20 at 00:51
  • 1
    You should *never* run `pip install bio` it is not related to biopython! Please read github issue I linked above – Chris_Rands Oct 11 '20 at 09:59