6

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.

Josh Pinto
  • 7,769
  • 22
  • 80
  • 128
  • Try a `sudo make uninstall` before a `sudo make install`. And start a `make clean` before a `make` – A.B. May 16 '15 at 10:48
  • Tried & failed. `sudo make uninstall` gave the error: `make: *** No rule to make target 'uninstall'. Stop.` – Josh Pinto May 16 '15 at 11:04
  • That's maybe a problem. I have an idea. Install `checkinstall` with `sudo apt-get install checkinstall` and start the installation again with `sudo checkinstall` and not with `sudo make install`. Checkinstall installs a deb package and overwrites your previous installation. Then open the package manager and remove the installed package. Then start the compilation again and use in future `checkinstall` and not `make install`. Read [this](http://askubuntu.com/a/624018/367165) for an explanation for `checkinstall`. – A.B. May 16 '15 at 11:09
  • do I replace `make` (by itself) with checkinstall? – Josh Pinto May 16 '15 at 11:25
  • no, not `make` only a `make install`: `sudo make install` is now `sudo checkinstall` – A.B. May 16 '15 at 11:29
  • Tried & failed again, I'm afraid. – Josh Pinto May 16 '15 at 12:15

2 Answers2

3

Without python-openbabel:

% python
Python 2.7.9 (default, Apr  2 2015, 15:33:21) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import openbabel
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named openbabel
>>>

% python
Python 2.7.9 (default, Apr  2 2015, 15:33:21) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pybel
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pybel
>>>

Install python-openbabel:

sudo apt-get install python-openbabel

Check:

% python  
Python 2.7.9 (default, Apr  2 2015, 15:33:21) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import openbabel
>>>

% python                     
Python 2.7.9 (default, Apr  2 2015, 15:33:21) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pybel
>>>
A.B.
  • 89,123
  • 21
  • 245
  • 323
1

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:

% /usr/bin/python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 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 that PYTHONPATH 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)

emre
  • 301
  • 2
  • 5