Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Biopython: ImportError: No module named Bio

trying to install Biopython on Fedora 21, Python 2.7. I've done the following

[mike@localhost Downloads](17:32)$ sudo pip2.7 install biopython
You are using pip version 6.1.1, however version 7.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting biopython
/usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading biopython-1.65.tar.gz (12.6MB)
    100% |████████████████████████████████| 12.6MB 33kB/s 
Installing collected packages: biopython
  Running setup.py install for biopython
Successfully installed biopython-1.65

And then

[mike@localhost Downloads](17:32)$ ipython
Python 2.7.9 |Anaconda 2.2.0 (64-bit)| (default, Mar  9 2015, 16:20:48) 

In [1]: import Bio
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-a7440e1156be> in <module>()
----> 1 import Bio

ImportError: No module named Bio

What am I doing wrong?

EDIT

I tried installing biopython using

sudo easy_install -f http://biopython.org/DIST/ biopython

and it installed it into /usr/lib/python2.7/site-packages/biopython-1.65-py2.7-linux-x86_64.egg/. Didn't work.

Then I tried installing it using the same command, without the sudo:

easy_install -f http://biopython.org/DIST/ biopython

which installed it into /home/mike/anaconda/lib/python2.7/site-packages/biopython-1.65-py2.7-linux-x86_64.egg

And that worked! Both for ipython and python. But why did it work...?

like image 513
Mike Avatar asked Oct 19 '22 06:10

Mike


2 Answers

One should be very careful when using pip and the like that it is the pip which goes along with the supposed Python interpreter.

I see that you are trying to import Bio from the Python interpreter you get by typing ipython. You can make sure that you invoke the pip of exactly this interpreter like so:

sudo ipython -m pip install biopython

Note that the installation is not exclusive to ipython. It is however exclusive to whatever Python installation ipython is installed on top of.

like image 51
jmd_dk Avatar answered Oct 21 '22 21:10

jmd_dk


It's not good practice to sudo pip, since it may install things under root permission, which is usually not granted to ordinary program.

The problem probably lies in library path. The most informative tools will be

import sys
print (sys.path)

and

which python
pip --version

And use pip install biopython --user to replace sudo pip

like image 27
shouldsee Avatar answered Oct 21 '22 22:10

shouldsee