installing openbabel with pip for linux in venv

2.5k Views Asked by At

I am trying to install openbabel with pip on a linux computer without root access and also using a virtual environment. I run the following command

pip install openbabel --user --log LOG

and then I get the following error:

Collecting openbabel
  Using cached openbabel-2.4.1.tar.gz (74 kB)
Building wheels for collected packages: openbabel
  Building wheel for openbabel (setup.py) ... error
  ERROR: Failed building wheel for openbabel
  Running setup.py clean for openbabel
Failed to build openbabel
Installing collected packages: openbabel
    Running setup.py install for openbabel ... error
ERROR: Command errored out with exit status 1: /users/name/env_for_pymatgen/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-b51wnefv/openbabel/setup.py'"'"'; __file__='"'"'/tmp/pip-install-b51wnefv/openbabel/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-4207icvx/install-record.txt --single-version-externally-managed --compile --install-headers /users/name/env_for_pymatgen/include/site/python3.6/openbabel Check the logs for full command output.

The main problems seems to be

Error: SWIG failed. Is Open Babel installed?
    You may need to manually specify the location of Open Babel include and library directories. For example:
      python setup.py build_ext -I/usr/local/include/openbabel-2.0 -L/usr/local/lib
      python setup.py install

I see many people had similar issues with setup.py and they are advised to go to the directory and run the same command again, but I don't know what directory I should go to...

EDIT

Would it work if I download openbabel from github and give the path to it?

1

There are 1 best solutions below

0
On

From my experience, instead of pip install <package_name>, download a wheel file from here which has python binaries built from source code found on PyPI.

After that, open a terminal where you downloaded .whl files and then type :

pip install nameOfYourFile.whl

in my case it's :

pip install openbabel-3.1.1-cp38-cp38-win32.whl

EDIT: be sure to download a version matching your python version otherwise the package will not install.

EDIT2: I honestly didn't notice that the answer is focused on Linux, so to answer your question, your most reliable option is to build it from source with the python bindings and swig flags enabled, this can be done by following the compiling instructions.

Those instructions still work for the latest version of openbabel in the GitHub repo as of the date of this edit, and i could successfully compile a working openbabel with the python bindings (pybel) on Ubuntu 21.10.