On Chemistry Stack Exchange I asked a question regarding Open Babel & Python being used together.
The problem is that the answer I was provided (by Geoff Hutchinson) requires Python to be able to import the module Pybel.
I have installed Open Babel on this PC via two ways, APT and source. I then deleted my APT installation after I realized pybel wasn't available for Python use and I decided to install from source with Python bindings.
To do so I followed this guide with the final command being customized to (running from ~/build
)
cmake ../openbabel-2.3.2 -DBUILD_GUI=ON -DPYTHON_BINDINGS=ON
which gave the output:
-- Using included inchi library.
-- Found wxWidgets: TRUE
-- Cairo found. PNG output will be supported.
-- Attempting to build the GUI
-- wxWidgets found => GUI will be built
CMake Warning (dev) at test/CMakeLists.txt:171 (include):
Syntax Warning in cmake code at
/home/fusion809/Downloads/openbabel-2.3.2/cmake/modules/UsePythonTest.cmake:54:14
Argument not separated from preceding token by whitespace.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at test/CMakeLists.txt:171 (include):
Syntax Warning in cmake code at
/home/fusion809/Downloads/openbabel-2.3.2/cmake/modules/UsePythonTest.cmake:54:31
Argument not separated from preceding token by whitespace.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at test/CMakeLists.txt:171 (include):
Syntax Warning in cmake code at
/home/fusion809/Downloads/openbabel-2.3.2/cmake/modules/UsePythonTest.cmake:57:25
Argument not separated from preceding token by whitespace.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at test/CMakeLists.txt:171 (include):
Syntax Warning in cmake code at
/home/fusion809/Downloads/openbabel-2.3.2/cmake/modules/UsePythonTest.cmake:57:39
Argument not separated from preceding token by whitespace.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Python bindings will be compiled
-- Could NOT find Ruby (missing: RUBY_INCLUDE_DIR RUBY_LIBRARY RUBY_CONFIG_INCLUDE_DIR) (found version "2.1.0")
-- Ruby library files NOT found. Ruby bindings will NOT be compiled.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fusion809/build
I should mention, however, that the first time I compiled Open Babel I forgot to add the -DBUILD_GUI
& -DPYTHON_BINDINGS
commands to the cmake line, so I had to run this new cmake command after I had initially compiled the software. Does this make any difference? Should I remove Open Babel and re-compile? If so do I have to delete some files in my /usr/
directory to (if so please mention them as I don't know which ones)? If relevant I am on 32 bit 15.04.
EDIT
I deleted my build directory's contents & started again and after the cmake command I ran:
make
sudo make install
export PYTHONPATH=/usr/local/lib:$PYTHONPATH
At the end of the output I received were these two lines:
-- Up-to-date: /usr/local/lib/openbabel.py
-- Up-to-date: /usr/local/lib/pybel.py
In a Python terminal I ran import openbabel
and import pybel
and it gave the output: ImportError: No module named ...
where ...
is openbabel or pybel, depending on which of the commands were executed, so I suspect it's a problem on my Python installation's end.
Without
python-openbabel
:Install
python-openbabel
:Check:
I had the same problem and figured out that I was using a python distribution (Anaconda) other than the original (the one provided by Ubuntu). Below is a potential workaround (if this is the case).
After installing python-openbabel using apt-get, check it with the system-provided python (in my case
/usr/bin/python
). You should be able to import openbabel:I tried to use
easy_install
provided by Anaconda to install openbabel & pybel but it was not successful. Then I copied the*openbabel*
and*pybel*
files in/usr/lib/python2.7/dist-packages/
to a folder thatPYTHONPATH
sees and it worked fine. I would appreciate if anyone has a nicer (cleaner) way to make Anaconda use of the package installed for system-provided python.(I wanted to comment to the answer but due to the lack of reputation I couldnt)