在化学堆栈交换上,我问了一个关于Open和Python一起使用的问题。
问题是,我提供的答案(由提供)要求Python能够导入Pybel模块。
我已经通过两种方式在这台PC上安装了Open,APT和源代码。当我意识到pybel不适合Python使用之后,我删除了我的APT安装,我决定使用Python绑定从源代码中安装。
为此,我遵循了本指南,并将最终命令定制为(从~/build运行)。
cmake ../openbabel-2.3.2 -DBUILD_GUI=ON -DPYTHON_BINDINGS=ON给出了输出:
-- 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命令之后运行:
make
sudo make install
export PYTHONPATH=/usr/local/lib:$PYTHONPATH在我收到的输出的末尾是这两行:
-- Up-to-date: /usr/local/lib/openbabel.py
-- Up-to-date: /usr/local/lib/pybel.py在Python终端中,我运行了import openbabel和import pybel,它给出了输出:ImportError: No module named ...,其中...是openbabel还是pybel,这取决于执行了哪些命令,因此我怀疑这是Python安装端的一个问题。
发布于 2015-05-16 12:24:30
没有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
>>>安装python-openbabel:
sudo apt-get install 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
>>>
% 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
>>>发布于 2015-12-16 12:10:29
我也遇到了同样的问题,发现我使用的是python发行版(Anaconda),而不是原来的版本(由Ubuntu提供的)。下面是一个潜在的解决办法(如果是这样的话)。
在使用After安装python之后,使用系统提供的python(在我的例子中是/usr/bin/python)检查它。您应该能够进口openbabel:
% /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安装的软件包,我会很感激。
(我想对答案发表评论,但由于缺乏声誉,我不能)
https://askubuntu.com/questions/624310
复制相似问题