"IndexError: list index out of range" on "import pybel"

1k Views Asked by At

I'm working on a web app django, when I install openbabel and try to import pybel i've got an error

I'm using a venv that was activate when I did all this commands

I install openbabel like this:

sudo apt-get install python-openbabel

I also tried :

sudo apt-get install openbabel libopenbabel-dev swig

Then I did :

pip install openbabel

after that, I've tried to import pybel (after importing openbabel)

This is actuall result :

>>> import pybel
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/etudiant/QuChemPedIA/QuChemPedIAProject/venv/lib/python3.5/site-packages/pybel.py", line 94, in <module>
    descs = _getpluginnames("descriptors")
  File "/home/etudiant/QuChemPedIA/QuChemPedIAProject/venv/lib/python3.5/site-packages/pybel.py", line 84, in _getpluginnames
    return [x.split()[0] for x in plugins]
  File "/home/etudiant/QuChemPedIA/QuChemPedIAProject/venv/lib/python3.5/site-packages/pybel.py", line 84, in <listcomp>
    return [x.split()[0] for x in plugins]
IndexError: list index out of range

Any help please?

1

There are 1 best solutions below

0
On BEST ANSWER

As @Manu mathew said, this is a bug, but not in Python's openbabel package but rather in the openbabel C library that it wraps (provided by the openbabel apt package).

The bug is fixed in version openbabel/2.3.2+dfsg-3 that for your Ubuntu Xenial (judging by your Python version) is not available.

So you need to upgrade your distro. The fix is available since Bionic but for best results, upgrade to the latest distro release (see below for explanation).


Beside that,

  • Installing python-openbabel apt package is useless because it's for Python 2. A package for Python 3 would be called "python3-openbabel" but there's no such package. So you do have to install the bindings from PyPI.
  • Installing a Python package both globally with apt-get and into venv with pip is redundant.
    • If you are using an old distro, you also open yourself to possible breakage when you link a new bindings package from PyPI against an old C library on your system. If the bindings package builds against your local library, it is likely meant to support this version, but who knows how much this combination was tested.
  • So normally, you should prefer the apt-get version of a Python package that wraps a local C library if one is available if you are using the system Python. You can make globally installed packages available in a venv by creating it with --system-site-packages.

But since in this case, there's no apt-get version of bindings available, you have to install the bindings from PyPI. In this case, you'd better have the C library version that corresponds to the bindings' version -- i.e. probably the latest -- since that combination was clearly extensively tested.