首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何安装pybel以便我的python环境能够识别它?

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

Ask Ubuntu用户
提问于 2015-05-16 03:33:35
回答 2查看 7.1K关注 0票数 6

化学堆栈交换上,我问了一个关于Open和Python一起使用的问题。

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

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

为此,我遵循了本指南,并将最终命令定制为(从~/build运行)。

代码语言:javascript
复制
cmake ../openbabel-2.3.2 -DBUILD_GUI=ON -DPYTHON_BINDINGS=ON

给出了输出:

代码语言:javascript
复制
-- 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

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

编辑

我删除了构建目录的内容&再次启动,在cmake命令之后运行:

代码语言:javascript
复制
make
sudo make install
export PYTHONPATH=/usr/local/lib:$PYTHONPATH

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

代码语言:javascript
复制
-- Up-to-date: /usr/local/lib/openbabel.py
-- Up-to-date: /usr/local/lib/pybel.py

在Python终端中,我运行了import openbabelimport pybel,它给出了输出:ImportError: No module named ...,其中...是openbabel还是pybel,这取决于执行了哪些命令,因此我怀疑这是Python安装端的一个问题。

EN

回答 2

Ask Ubuntu用户

回答已采纳

发布于 2015-05-16 12:24:30

没有python-openbabel

代码语言:javascript
复制
% 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
>>>

安装python-openbabel

代码语言:javascript
复制
sudo apt-get install python-openbabel

检查:

代码语言:javascript
复制
% 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
>>>
票数 3
EN

Ask Ubuntu用户

发布于 2015-12-16 12:10:29

我也遇到了同样的问题,发现我使用的是python发行版(Anaconda),而不是原来的版本(由Ubuntu提供的)。下面是一个潜在的解决办法(如果是这样的话)。

在使用After安装python之后,使用系统提供的python(在我的例子中是/usr/bin/python)检查它。您应该能够进口openbabel:

代码语言:javascript
复制
% /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
>>>

我试着使用Anaconda提供的easy_install安装openbabel & pybel,但没有成功。然后,我将*openbabel**pybel*文件在/usr/lib/python2.7/dist-packages/中复制到PYTHONPATH看到的文件夹中,并且运行良好。如果有人有更好(更干净)的方式让Anaconda使用为系统提供的python安装的软件包,我会很感激。

(我想对答案发表评论,但由于缺乏声誉,我不能)

票数 1
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/624310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档