How to install biopython in jupyter notebook

After installing a package, you can confirm that the package was installed correctly by opening a Jupyter Notebook in that environment, importing the package and displaying its help text. In this example we will use the BioPython package.

  1. Start Navigator.

  2. To install the BioPython package, follow the instructions in Managing packages.

  3. Click the icon to open a Jupyter Notebook.

  4. In the Jupyter Notebook, click the New button and select your installed Python version.

    How to install biopython in jupyter notebook

  5. Copy and paste the following code into the first cell:

  6. To run the code, in the menu bar, click Cell then select Run Cells, or use the keyboard shortcut Ctrl-Enter.

    The BioPython help text is displayed.

I am trying to install biopython in Jupyter Notebook, Anaconda, Ubuntu 16.04. I follow the procedure in biopython website and it runs on python.

Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import Bio
>>> 

However, it does not work on Jupyter Notebook.

from Bio.PDB.PDBParser import PDBParser

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
 in ()
      1 # biopython testing
----> 2 from Bio.PDB.PDBParser import PDBParser

ModuleNotFoundError: No module named 'Bio'

conda list also how biopython installed.

biopython                 1.72             py36h04863e7_0    anaconda
blas                      1.0                         mkl    anaconda
ca-certificates           2019.1.23                     0  
certifi                   2019.3.9                 py36_0  
intel-openmp              2019.3                      199    anaconda
libedit                   3.1.20181209         hc058e9b_0  
libffi                    3.2.1                hd88cf55_4  
libgcc-ng                 8.2.0                hdf63c60_1  
libgfortran-ng            7.3.0                hdf63c60_0    anaconda
libstdcxx-ng              8.2.0                hdf63c60_1  
mkl                       2019.3                      199    anaconda
mkl_fft                   1.0.10           py36ha843d7b_0    anaconda
mkl_random                1.0.2            py36hd81dba3_0    anaconda
ncurses                   6.1                  he6710b0_1  
numpy                     1.16.2           py36h7e9f1db_0    anaconda
numpy-base                1.16.2           py36hde5b4d6_0    anaconda
openssl                   1.1.1b               h7b6447c_1  
pip                       19.0.3                   py36_0  
python                    3.6.8                h0371630_0  
readline                  7.0                  h7b6447c_5  
setuptools                40.8.0                   py36_0  
sqlite                    3.27.2               h7b6447c_0  
tk                        8.6.8                hbc83047_0  
wheel                     0.33.1                   py36_0  
xz                        5.2.4                h24c3975_4  
zlib                      1.2.11               h7b6447c_3  

Is there any reason why it is not working? I appreciate any help.

The last post in the Protein Structure series ended with:

“In the next post, I will use Biopython to import a structure and do some fairly introductory calculations”.

In this post I will pick up from there.

While there are multiple ways in which one can make use of Biopython, I will use it through the Jupyter Notebook. So the first order of business would be to set it up to make use of Python. The instructions to do this were posted earlier in “Setting up Python“.

So assuming you have gotten Python up and running in the Jupyter Notebook, we will start by import biopython. To do this type the command

 import Bio 

You will write this in the available box (called a cell) and when you are finishing writing the command, you will run it by pressing the Cntrl + Enter key together. The square bracket next to the cell [ ] which show an asterix (*) symbol indicating the command is running. When the instruction in the cell has finished processing it will show a number.

In the Jupyter Notebook you can always re-run a cell, but in that case the number in the square bracket will still be updated.

However in this case it is highly likely you will get an error message saying that the module you have just tried loading isn’t available (Figure 1).

How to install biopython in jupyter notebook

Figure 1: Error message when trying to load Biopython. This is a typical error message when trying to load a module which is either not installed or is installed but not visible to Python.

This is because you have just made a “FRESH” install and therefore nothing else but what you have installed is available. Biopython is not wrapped in this install which is why you will receive this message. If for some reason you don’t,  you can skip the next step where I show how to install Biopython.

To install biopython, type in a cell:

 !conda install --yes biopython 

and press Cntrl + Enter to run the command. Each cell can have more than one command as well. This installation process may be very quick or take a long time depending on your internet connection and your computer’s speed.

Make sure the process is successful. You should see and output like in Figure 2 if everything happens according to plan. I cannot comment on the type of errors which may occur, so if you have difficulty installing, please get in touch ( or use the Facebook page to send me a message)

How to install biopython in jupyter notebook

Figure 2: Successful installation of Biopython using conda within Jupyter Notebook.

At this point you have successfully installed Biopython and are now ready to use it.

Other stuff:

Although I have shown how to install Biopython and load it, we will be making use of many other modules as well. Fortunately many of these modules will come installed by default with Python. We will make use of these regularly. As an example let’s try and work something out.

For example, assume a scenario where you want to import a data file which is located on your computer’s hard-drive at a certain location. Before you can import it, you must be able to “set the path” to that file. There are different ways of doing this. The way I will be doing this is that every time we will be using Python, we will make a “Working Directory” and keep all files required for a project inside that folder. This will limit the need to change paths.

Let’s look at an example to clarify this. To detect paths in Python you will need a module called “os”. You will load this module using:

 import os 

This is good, because when you import a module, all functions in that module become available. When you load the module “os”, the function “getcwd” becomes available for use. To make use of this method type

 print os.getcwd() 

where “os” is the module and “getcwd()” is a method of that module which you will access through the use of “dot”. The command os.getcwd() command will tell you the current location available to Python. Remember that if you create a file and want to read a file, this is the location Python is looking at. You must put your files in this location. If you don’t want to use this location you can change it. To change the path, you can make use of another method called “chdir(new_path)”. This method takes as its input (input is the value you will pass within the brackets, i.e. by replacing the string new_path) the new path which you would like to use. See Figure 3.

How to install biopython in jupyter notebook

Figure 3: The first cell shows how to load the “os” module to make use of methods available in it. The second cell makes use of “os.getcwd()” to find out the current location visible to Python. Since I am using Linux and the way Jupyter is set up on my computer, it points to my user home, which is ‘/home/proteinmechanic/’. On your computer this path will be different. If you are on windows, it will also include your drive letter (e.g. C:\). In the following cell the “os.chdir(path)” is used, where path is the full path of the new location. Again, I chose something on my computer. You will select whatever is convenient for you. After running the “os.chdir(path)” command, we can check to see if the path has indeed been changed. The output from “os.getcwd()” shows that the path has now been updated.

This series is not on “Learning Python” but just getting equipped with enough of it to make it work and do what you want it to do. So I will end this post here. In the next post we will start from here and start making use of the PDB structures, which we will import from a certain location and process to get analytics.

For you to be able to follow the next post smoothly, make sure to follow the instructions in the last and current posts. If you have any difficulty, please reach me through the IDRACK Facebook page.

How do I install Biopython in Anaconda?

Install Anaconda Navigator, go to " Environments " and select the appropriate environment (base or your own) and click " not installed ". Scroll down to biopython click the box and then install...

How do I know if Biopython is installed?

3. Confirm that Biopython has been correctly installed by starting a Python terminal session and entering this line: import Bio If you do not receive an error message, then Biopython has been properly installed!

How do I install a bio module in Python?

Installation Instructions.
pip install biopython..
pip install biopython --upgrade..
pip uninstall biopython..
python -m ensurepip..
python3.6 -m pip install biopython pypy -m pip install biopython..
C:\Python36\Scripts\pip install biopython..
xcode-select --install..
python setup.py build python setup.py test python setup.py install..

Does Anaconda have Biopython?

The default Conda channel does have Biopython, but is often out of date. Note Conda is available on Windows, Mac OS X and Linux, and covers far more than just Python.