如何安装 pybel 以便我的 python 环境识别它?

Jos*_*nto 6 python cmake openbabel

Chemistry Stack Exchange 上,我问了一个关于 Open Babel 和 Python 一起使用的问题。

问题是我提供的答案(由 Geoff Hutchinson 提供)要求 Python 能够导入模块 Pybel。

我已经通过两种方式在这台 PC 上安装了 Open Babel,APT 和源代码。在我意识到 pybel 不可用于 Python 之后,我删除了我的 APT 安装,我决定从源代码安装 Python 绑定。

为此,我按照本指南将最终命令定制为(从 运行~/build

cmake ../openbabel-2.3.2 -DBUILD_GUI=ON -DPYTHON_BINDINGS=ON
Run Code Online (Sandbox Code Playgroud)

这给出了输出:

-- 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
Run Code Online (Sandbox Code Playgroud)

然而,我应该提一下,我第一次编译 Open Babel 时忘记将-DBUILD_GUI&-DPYTHON_BINDINGS命令添加到 cmake 行,所以我必须在最初编译软件后运行这个新的 cmake 命令。这有什么区别吗?我应该删除 Open Babel 并重新编译吗?如果是这样,我是否必须删除我/usr/目录中的某些文件(如果是这样,请提及它们,因为我不知道是哪些文件)?如果相关,我使用的是 32 位 15.04。

编辑

我删除了构建目录的内容并重新启动,然后在运行 cmake 命令之后:

make
sudo make install
export PYTHONPATH=/usr/local/lib:$PYTHONPATH
Run Code Online (Sandbox Code Playgroud)

在我收到的输出的末尾是这两行:

-- Up-to-date: /usr/local/lib/openbabel.py
-- Up-to-date: /usr/local/lib/pybel.py
Run Code Online (Sandbox Code Playgroud)

在Python终端我跑import openbabelimport pybel,它给了输出:ImportError: No module named ...这里...是openbabel或pybel,取决于命令哪个被执行,所以我怀疑它在我的Python安装结束的问题。

A.B*_*.B. 3

没有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
>>>
Run Code Online (Sandbox Code Playgroud)

安装python-openbabel

sudo apt-get install python-openbabel
Run Code Online (Sandbox Code Playgroud)

查看:

% 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
>>>
Run Code Online (Sandbox Code Playgroud)