1

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.

matebende
  • 543
  • 1
  • 7
  • 21
beliz
  • 402
  • 1
  • 5
  • 25
  • 1
    if you followed the advice on compiling `openbabel` from source, the bindings should already be compiled, you should be able to do `from openbabel import pybel` – FlyingTeller May 13 '20 at 08:23

2 Answers2

4

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.

beliz
  • 402
  • 1
  • 5
  • 25
1

I have exactly the same problem. It works with the following code:

from openbabel import pybel
mymol = pybel.readstring("smi","CCN(CC)CC")
mymol
Wang
  • 1,314
  • 14
  • 21
  • Thanks but actually this also didn't work. Turns out I imported the wrong pybel... – beliz May 26 '20 at 12:37
  • 1
    you need to uninstall the wrong pybel first. I made the same mistake. `pip uninstall pybel` – Wang May 26 '20 at 15:26