【问题标题】:How to Install openbabel for Python 3.6 on macOS Sierra 10.12.3如何在 macOS Sierra 10.12.3 上为 Python 3.6 安装 openbabel
【发布时间】:2017-06-30 22:01:51
【问题描述】:

我正在使用 Python 编写一个脚本来处理我的博士期间的一些化学结构。我想为 python 安装 openbabel 库。我尽力了,但我无法在 Windows 上安装它。我之前在How do I install openbabel for Python 3.6 in Windows 10? 上发布了一个关于在 Windows 上安装它的问题,但找不到解决方案。该解决方案安装了库,但它不起作用并且无法连接到 SWIG。 不,我试图将它安装在我的办公室计算机上,这是过去 5 个小时的 mac,但我不知道发生了什么。 我尝试从 Opnbabel 的源代码安装它并将其与 python3 链接,但它出现了问题。 如果我使用以下命令:

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

它成功地将它链接到我不想要的 Python 2.7。当我尝试以下选项时,它会给出如下所示的错误:

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

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

在大量成功输出后,最后给出以下错误:

-- 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".

我不确定为什么它将 Python 检测为 v1.4 -- Found PythonInterp: /usr/bin/python3.6 (found version "1.4") 而不是找到 v.3.5。 我也用 python 3.6 尝试了所有过程,但发生了同样的错误。我也在使用从 github 获得的 openbabel,据说它在以下帖子中使用这些命令:http://forums.openbabel.org/OpenBabel-for-Python-3-td4659432.html 但它也不起作用。 请帮助我,因为我需要这个模块来进行研究。 谢谢

【问题讨论】:

    标签: python macos python-3.x macos-sierra openbabel


    【解决方案1】:

    我找到了解决方案。这是详细的解决方案:

    1. 从原始源下载 Open Babel (https://github.com/openbabel/openbabel)

    2. 解压并 cd 进入其中 (openbabel-master)

    3. 创建一个目录“build”并 cd 进入。

    4. 运行以下命令:

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

      在上面的命令中,“-DPYTHON_EXECUTABLE”开关告诉它找到 Python3 解释器的路径。您可以在终端通过which python3查看。

    5. make

    6. make install

    全部完成! :)

    【讨论】:

    • 我这样做了,但是当我尝试导入 openbabel 时,我没有得到名为 'openbabel' 的模块。还有一步吗?安装似乎已经完成
    • @SpencerTrinh 您必须将 openbabel 的安装目录关联到 python 才能使绑定生效。如果你在make install 之后运行export PYTHONPATH=/usr/local/lib:$PYTHONPATH 并尝试从python 导入openbabel 就可以了。
    • 我使用了不同的策略,但现在导入openbabel时出现错误github.com/openbabel/openbabel/issues/2413
    猜你喜欢
    • 2017-08-30
    • 1970-01-01
    • 2017-06-19
    • 2017-06-28
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    相关资源
    最近更新 更多