Search code examples
pythonmacospipopenbabelpybel

importing openbabel wrapper pybel for macos without conda


Previously I asked how to install openbabel for macos here. Now I also need to install the openbabel python wrapper pybel. I tried pip install pybel and it was installed. Then, while I was following the tutorial,

import openbabel
import pybel
mymol = pybel.readstring("smi", "CCCC")

I got the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'pybel' has no attribute 'readstring'

It turns out other people had similar issues and in fact I found in the mailing list that, I quote

'I guess you installed pybel via pip install pybel, which is the "wrong" pybel'

Then they give a solution which is pip install openbabel, which is not possible for macos.

A solution is to use conda to install openbabel but I am not using conda and I would like to keep it that way so I am looking for a solution which does not require conda.


Solution

  • I found the solution, you can brew install open-babel and then give the path to homebrewed library of python site-packages. For me the following works:

    import sys
    sys.path.append('/usr/local/lib/python3.8/site-packages')
    

    Then you can

    import openbabel
    from openbabel import pybel
    

    and so on.