Error importing Biopython module
2
0
Entering edit mode
9.2 years ago
pmr • 0

I want to do a cluster analysis using the distance functions in Biopython. But, the following line of code:

from Bio.Cluster import distancematrix

results in the following error:

ImportError: No module named 'Bio.Cluster'

Does anyone have an idea why this might happen?

biopython python 3 python Biopython • 7.2k views
ADD COMMENT
0
Entering edit mode

What operating system do you use? Did you install Biopython correctly? Does this happen when you try to import other Biopython components (eg. import Bio) or is this specific to the Cluster module?

ADD REPLY
0
Entering edit mode

I use OSX. Yes I think Biopython is correctly installed, because I am able to import other modules so I suspect this is specific for Bio.Cluster. The following, for example, works fine:

from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
ADD REPLY
0
Entering edit mode

This looks like a problem with the Bio.Cluster package. We should wait for someone from the Bio Cluster team to take a look at this post.

ADD REPLY
2
Entering edit mode
9.2 years ago
Peter 6.0k

One possible problem is that you installed Biopython without having NumPy. This would result in not installing the cluster module which uses C code with NumPy. If so, you may need to reinstall Biopython. If this is the problem this won't work either:

from Bio import KDTree

Alternatively, it might be you didn't install Biopython properly and have somehow managed to get access to only the pure-Python parts? That is possible if you're in the Biopython source code directory when you run Python, or if you have set the $PYTHONPATH to include the Biopython source code. In this case the following will probably also fail:

from Bio import trie

In addition to trying these two imports, could you add more details about how you installed Biopython? e.g. Which version of OS X, XCode, Python, NumPy, Biopython.

ADD COMMENT
0
Entering edit mode

I reinstalled Biopython and I no longer get the import error! Thanks for all your suggestions.

I did get quite a few warnings when reinstalling Biopython (using easyinstaller), do you have any thoughts on why I get these? Could they be related to the import issue?

Searching for biopython
Reading http://biopython.org/DIST/
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/setuptools-12.0.5-py3.4.egg/pkg_resources/__init__.py:2510: PEP440Warning: 'biopython (corba-0.2.1)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/setuptools-12.0.5-py3.4.egg/pkg_resources/__init__.py:2510: PEP440Warning: 'biopython (corba-0.3.0)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
Best match: biopython 1.65
Downloading http://biopython.org/DIST/biopython-1.65.zip
Processing biopython-1.65.zip
Writing /tmp/easy_install-jqt75dle/biopython-1.65/setup.cfg
Running biopython-1.65/setup.py -q bdist_egg --dist-dir /tmp/easy_install-jqt75dle/biopython-1.65/egg-dist-tmp-jgo6r6jw
warning: no previously-included files matching '.cvsignore' found under directory '*'
warning: no previously-included files matching '*.pyc' found under directory '*'
ld: warning: ignoring file build/temp.macosx-10.6-intel-3.4/Bio/cpairwise2module.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x07 0x00 0x00 0x01 0x03 0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being linked (i386): build/temp.macosx-10.6-intel-3.4/Bio/cpairwise2module.o
ld: warning: ld: warning: ignoring file build/temp.macosx-10.6-intel-3.4/Bio/triemodule.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x07 0x00 0x00 0x01 0x03 0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being linked (i386): build/temp.macosx-10.6-intel-3.4/Bio/triemodule.oignoring file build/temp.macosx-10.6-intel-3.4/Bio/trie.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x07 0x00 0x00 0x01 0x03 0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being linked (i386): build/temp.macosx-10.6-intel-3.4/Bio/trie.o

ld: warning: ignoring file build/temp.macosx-10.6-intel-3.4/Bio/Nexus/cnexus.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x07 0x00 0x00 0x01 0x03 0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being linked (i386): build/temp.macosx-10.6-intel-3.4/Bio/Nexus/cnexus.o
ld: warning: ld: warning: ignoring file build/temp.macosx-10.6-intel-3.4/Bio/Cluster/clustermodule.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x07 0x00 0x00 0x01 0x03 0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being linked (i386): build/temp.macosx-10.6-intel-3.4/Bio/Cluster/clustermodule.oignoring file build/temp.macosx-10.6-intel-3.4/Bio/Cluster/cluster.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x07 0x00 0x00 0x01 0x03 0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being linked (i386): build/temp.macosx-10.6-intel-3.4/Bio/Cluster/cluster.o

ld: warning: ld: warning: ignoring file build/temp.macosx-10.6-intel-3.4/Bio/KDTree/KDTree.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x07 0x00 0x00 0x01 0x03 0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being linked (i386): build/temp.macosx-10.6-intel-3.4/Bio/KDTree/KDTree.oignoring file build/temp.macosx-10.6-intel-3.4/Bio/KDTree/KDTreemodule.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x07 0x00 0x00 0x01 0x03 0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being linked (i386): build/temp.macosx-10.6-intel-3.4/Bio/KDTree/KDTreemodule.o

ld: warning: ignoring file build/temp.macosx-10.6-intel-3.4/Bio/Motif/_pwm.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x07 0x00 0x00 0x01 0x03 0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being linked (i386): build/temp.macosx-10.6-intel-3.4/Bio/Motif/_pwm.o
ld: warning: ignoring file build/temp.macosx-10.6-intel-3.4/Bio/motifs/_pwm.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x07 0x00 0x00 0x01 0x03 0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being linked (i386): build/temp.macosx-10.6-intel-3.4/Bio/motifs/_pwm.o
zip_safe flag not set; analyzing archive contents...
Bio.__pycache__.cpairwise2.cpython-34: module references __file__
Bio.__pycache__.trie.cpython-34: module references __file__
Bio.Cluster.__pycache__.cluster.cpython-34: module references __file__
Bio.Entrez.__pycache__.Parser.cpython-34: module references __path__
Bio.KDTree.__pycache__._CKDTree.cpython-34: module references __file__
Bio.Motif.__pycache__._pwm.cpython-34: module references __file__
Bio.motifs.__pycache__._pwm.cpython-34: module references __file__
Bio.Nexus.__pycache__.cnexus.cpython-34: module references __file__
creating /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/biopython-1.65-py3.4-macosx-10.6-intel.egg
Extracting biopython-1.65-py3.4-macosx-10.6-intel.egg to /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
Adding biopython 1.65 to easy-install.pth file

Installed /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/biopython-1.65-py3.4-macosx-10.6-intel.egg
Processing dependencies for biopython
Finished processing dependencies for biopython
ADD REPLY
0
Entering edit mode

We don't recommend easyinstallster, and I'm not vary familiar with it. The warning about biopython (corba-0.3.0) is puzzling, not sure where that could be coming from? But in any case, reinstalling seems to have worked?

ADD REPLY
0
Entering edit mode

Yes it has worked fine since I reinstalled. Thank you.

ADD REPLY

Login before adding your answer.

Traffic: 2610 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6