简体   繁体   English

如何在macOS Sierra 10.12.3上为Python 3.6安装openbabel

[英]How to Install openbabel for Python 3.6 on macOS Sierra 10.12.3

I am using Python for making a script to work with some chemical structures in my PhD. 我正在使用Python编写脚本来处理博士学位中的某些化学结构。 I want to install openbabel libraries for python. 我想为python安装openbabel库。 I tried my best but I could not install it on Windows. 我已尽力而为,但无法在Windows上安装它。 I posted a question earlier about installing it on Windows at How do I install openbabel for Python 3.6 in Windows 10? 我早些时候发布了一个有关在Windows上安装它的问题,该问题在Windows 10如何为Python 3.6安装openbabel? but could not find a solution. 但找不到解决方案。 The solution installed the library but it does not work and could not connect to SWIG. 该解决方案安装了该库,但无法运行,并且无法连接到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. 不,我试图在过去5个小时的Mac办公电脑上安装它,但我不知道发生了什么。 I tried to install it from source code of Opnbabel and link it with python3 but it is making problem. 我试图从Opnbabel的源代码安装它,并将其与python3链接,但是这引起了问题。 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. 它成功地将其链接到我不想要的Python 2.7。 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. 我不确定为什么它将Python检测为v1.4 -- Found PythonInterp: /usr/bin/python3.6 (found version "1.4")而不是找到v.3.5。 I tried all the procedure with python 3.6 as well but the same errors occur. 我也尝试了python 3.6的所有过程,但是发生了相同的错误。 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. 我还使用从github获得的openbabel,据说在下面的文章中使用这些命令: http : //forums.openbabel.org/OpenBabel-for-Python-3-td4659432.html但它不起作用也一样 Please help me as I require this module for my research. 请帮助我,因为我需要此模块来进行研究。 Thanks 谢谢

I found the solution for that. 我找到了解决方案。 Here is the detailed solution: 这是详细的解决方案:

  1. Download Open Babel from its original source ( https://github.com/openbabel/openbabel ) 从其原始来源( https://github.com/openbabel/openbabel )下载Open Babel

  2. Extract it and cd into it (openbabel-master) 解压缩并放入CD(openbabel-master)

  3. Make a directory “build” and cd into it. 使目录“ build”并进入cd。

  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. 在上面的命令中,“-DPYTHON_EXECUTABLE”开关告诉它找到Python3解释器的路径。 You can check it by which python3 at a terminal. 您可以在终端上通过which python3进行检查。

  5. make

  6. make install

All Done! 全部做完! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM