How to Install openbabel for Python 3.6 on macOS Sierra 10.12.3

2.3k views Asked by At

I am using Python for making a script to work with some chemical structures in my PhD. I want to install openbabel libraries for python. I tried my best but I could not install it on Windows. I posted a question earlier about installing it on Windows at How do I install openbabel for Python 3.6 in Windows 10? but could not find a solution. The solution installed the library but it does not work and could not connect to SWIG. No I am trying to install it on my office computer which is a mac for past 5 hours but I could not figure what is going on. I tried to install it from source code of Opnbabel and link it with python3 but it is making problem. If I use the following command:

cmake ../ -DPYTHON_BINDINGS=ON -DRUN_SWIG=ON

It successfully links it to Python 2.7 which I do not want. When I try the following options, it gives the error shown below:

cmake ../ -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_BINDINGS=ON -DRUN_SWIG=ON

OR

cmake ../ -DRUN_SWIG=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -DPYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5m.dylib -DPYTHON_BINDINGS=ON

It gives the following error at the end after a lot of successful output:

-- Found PythonInterp: /usr/bin/python3.6 (found version "1.4") 
-- Found SWIG: /usr/local/bin/swig (found version "3.0.12") 
-- Found SWIG: /usr/local/bin/swig (found suitable version "3.0.12", minimum required is "2.0") 
-- Found PythonLibs: /usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6m.dylib (found version "3.6.0") 
-- Python bindings will be compiled
CMake Error at scripts/CMakeLists.txt:120 (install):
install TARGETS given no LIBRARY DESTINATION for module target
"bindings_python".
CMake Error at scripts/CMakeLists.txt:123 (install):
install FILES given no DESTINATION!
CMake Error at scripts/CMakeLists.txt:126 (install):
install FILES given no DESTINATION!
-- Configuring incomplete, errors occurred!
See also "/usr/local/Cellar/obabel/openbabel-master/ali/CMakeFiles/CMakeOutput.log".
See also "/usr/local/Cellar/obabel/openbabel-master/ali/CMakeFiles/CMakeError.log".

I am not sure why It detects the Python as v1.4 -- Found PythonInterp: /usr/bin/python3.6 (found version "1.4") instead of finding v.3.5. I tried all the procedure with python 3.6 as well but the same errors occur. I am also using the openbabel obtained from github which was said to be working with these commands at the following post: http://forums.openbabel.org/OpenBabel-for-Python-3-td4659432.html But it doesn't work as well. Please help me as I require this module for my research. Thanks

1

There are 1 answers

3
Hashmi On

I found the solution for that. Here is the detailed solution:

  1. Download Open Babel from its original source (https://github.com/openbabel/openbabel)

  2. Extract it and cd into it (openbabel-master)

  3. Make a directory “build” and cd into it.

  4. RUN the following command:

    cmake ../ -DPYTHON_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/3.5/bin/python3 -DPYTHON_BINDINGS=ON -DRUN_SWIG=ON

    In the command above, the “-DPYTHON_EXECUTABLE” switch tells it the path where Python3 interpretor is found. You can check it by which python3 at a terminal.

  5. make

  6. make install

All Done! :)