biopython no module named Bio
Asked Answered
V

14

18

FYI: this is NOT a duplicate!

Before running my python code I installed biopython in the cmd prompt:

pip install biopython

I then get an error saying 'No module named Bio' when try to import it in python

import Bio

The same thing happens with

import biopython     

It should be noted I have updated PIP and run python 3.5.2
I appreciate anyone's help.

Viscometer answered 16/4, 2018 at 1:33 Comment(4)
Tell us a little about your system, please. Windows or Linux? Are you running multiple versions of python? Have you tried venv? Usually, using a virtual environment will make these problems go away.Lovesome
I’m using Windows 10 and Jupyter notebook. I tried using python 2.7 and get same ‘no module ‘ error.Viscometer
what do you get with pip --version?Geraldgeralda
Gabriel -- again, almost without fail when I help with these issues it is because of a mismatch between pip install and runtime. That is why I continue to recommend using venv. If you do your pip installs in the same venv that you run your code from, you will avoid mismatches. Virtual environments are easy to use and well worth your time to learn; docs.python.org/3.5/library/venv.htmlLovesome
T
18

use this:

pip3 install biopython

and then import Bio worked for me

Tapeworm answered 16/4, 2018 at 1:37 Comment(4)
thank you for your quick response! Because I was having the 'fatal error in launcher' i used "-m pip3 install biopython" and it says "no module named pip3". I used "-m pip install biopython" and it already tells me I have it installed.Viscometer
biopython.org/DIST/docs/install/Installation.html#htoc7 It says the release is for python3.3 only, might be the problem because of ur python3 version!Tapeworm
@TanayAgrawal That is outdated information. BioPython works with Python 3.5, see biopython.org/wiki/DownloadDavid
@Gabriel, try sudo apt install python3-pip first (see here linuxize.com/post/how-to-install-pip-on-ubuntu-18.04)Nolannolana
A
4

When I came across this problem I noticed that after I installed biopython using pip install biopython the module directory in the site-packages folder was written with lowercase instead of uppercase letters. All in all, the folder was named bio instead Bio, so I just renamed the folder and everything started to work just fine. I am new to programing so I am aware this isn't the most elegant solution but it worked for me so I hope my answer will be useful to some of you. :)

Aixenprovence answered 31/10, 2019 at 20:33 Comment(1)
This is a known issue. Basically at some point you accidentally ran pip install bio (or pip install Bio) instead of pip install biopython. Running pip install bio/Bio installs a module completed unrelated to Biopython. Rather than just re-naming you should run pip uninstall bio; pip uninstall Bio; pip install biopython github.com/biopython/biopython/issues/2363Goodden
C
3

I just hit this issue with the problem being lower-case bio vs upper-case Bio. Turns out the problem was that it installs differently on python 2 and 3. In Python 2 you do import Bio, but in python 3 import bio. If you're hitting this issue it might be for the same reason, and the solution is probably to make sure you use the right name for the Python version you're on.

Chercherbourg answered 4/12, 2019 at 21:19 Comment(0)
M
3

pip3didn't fully work for me as there was a problem with importing a function.

conda install biopython 

✔️ worked for me.

Metalepsis answered 25/3, 2020 at 20:18 Comment(0)
S
2

Rename the site-package name from bio into Bio

C:\Users\user\Anaconda3\Lib\site-packages\bio

C:\Users\user\Anaconda3\Lib\site-packages\Bio

it works for me!

Suffocate answered 19/3, 2020 at 9:9 Comment(1)
Same issue on Mac OS. There the path is /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Bio.Skim
O
1

On windows it installs the bio package in a top level directory named bio with lower case b. To fix the problem rename the directory to upper case b, Bio.

Obviously the biopython people don't pay much attention to the win

Ordain answered 4/3, 2020 at 15:51 Comment(0)
G
1

As stated by others Biopython appears to work only with python 3.5. In my current environment I had python 2.7, so creating a Conda environment with python 3.5 solved the problem for me.

conda create -n mypython3.5 python=3.5

Then activate the environment:

conda activate mypython3.5

And installing Biopython on it:

conda install -c conda-forge biopython

In my case I also had to install Prodigal in the new environment to run my script:

conda install -c bioconda prodigal

Grating answered 17/3, 2021 at 4:2 Comment(0)
U
0

In my case (MacOS X Catalina, python 3.7.6 installed by brew), I had to install it with

python -m pip install Bio

(uppercase) but use it with

from bio import pairwise2

and the worse is that I had to change the code of the package: I went into python3.7/site-packages/bio/pairwise2.py, line 246, changed

from Bio import BiopythonWarning

into

from bio import BiopythonWarning

I hate changing the code of the package, on the next update it won't work again… Please do something to fix this bio/Bio issue.

Unger answered 15/2, 2020 at 23:29 Comment(0)
U
0

I had the same error. it turns out

import Bio

works

instead of import biopython !

Untune answered 27/3, 2020 at 23:6 Comment(0)
G
0

In my case, i got an error while trying to install BioPython, "BioPython requires python version greater than 3.6"

So installing the latest version fixed it for me.

Grider answered 9/6, 2020 at 16:36 Comment(0)
G
0

I could not import biopython when running python on windows.

I tried several solutions by changing the directory names to upper/lower case as https://mcmap.net/q/658001/-biopython-no-module-named-bio and also different way of calling when import using "Bio", "bio", "biopyhton". None was working.

But, It works in linux as simple as in manual guideliens, I did pip3 install biopython and with import Bio works!

Gauntlett answered 27/7, 2020 at 10:2 Comment(0)
A
0

I tried pip3 install biopython but it didn't work for me.

But this works! - !pip install biopython

Antiserum answered 23/10, 2020 at 17:30 Comment(0)
K
0

I tried all of the above with no success. I switched from Python 3.8 to Python 3 and that worked.

Kennykeno answered 20/3, 2021 at 23:53 Comment(0)
G
0

If you encounter this problem now and find your python version to be higher than 3.8: create a virtual environment, downgrade python to 3.8 and if you are using jupyter notebook, install it again in your environment..

Geraldine answered 1/12, 2021 at 14:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.