1

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?

beliz
  • 402
  • 1
  • 5
  • 25
  • 2
    You need the C openbabel development headers to compile the python module. Check if it's available in your distro's repository. – jordanm May 20 '20 at 16:09
  • 1
    http://openbabel.org/wiki/Category:Installation – phd May 20 '20 at 16:09
  • @jordanm how can I check that? – beliz May 20 '20 at 16:09
  • 1
    @beliz depeneds on your distro – jordanm May 20 '20 at 16:10
  • @phd I checked that page already... I tried building it myself and did `export PYTHONPATH`. This worked for `import openbabel` but I am also using pymatgen, which requires openbabel for some packages and pymatgen fails to find openbabel. This is why I tried `pip install` and I can't find any documentation on this link and I can't use `conda` – beliz May 20 '20 at 16:13
  • @jordanm I found this link: https://software.opensuse.org/package/openbabel but it has version 2.4.1, I need version at least 3.0 – beliz May 20 '20 at 16:19
  • 2
    @beliz https://software.opensuse.org/package/openbabel3 – jordanm May 20 '20 at 16:31
  • @jordanm thanks, this worked for me. maybe you can post it as an answer and I can accept it so that the question will be closed. – beliz May 20 '20 at 17:10

1 Answers1

2

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.

mimminou
  • 23
  • 6