编译和安装Cantera Python模块时遇到问题

3 投票
3 回答
2047 浏览
提问于 2025-04-17 06:32

我正在尝试在Ubuntu Linux上安装Cantera这个Python模块。为了参考,我使用了这些说明:安装Cantera。在运行了./preconfigmake之后,我遇到了以下错误:

fatal error: numarray/arrayobject.h: No such file or directory

根据preconfig文件,

# If numpy was installed using the --home option, set this to the
# home directory for numpy. This will be needed for all numpy installations
# that don't put the include files into python's native include directory.
#NUMPY_HOME=${NUMPY_HOME:="$HOME/python_packages"}

我使用的是Enthought Python Distribution的学生版本,所以我想也许我需要把最后一行改成:

NUMPY_HOME=${NUMPY_HOME:="/usr/local/EPD/lib/python2.7/site-packages/"}

但这样还是不行。我仍然遇到同样的错误。有什么想法吗?我已经安装了python-dev来修复之前的一个错误,所以这不是问题所在。

3 个回答

1

我们之前尝试过只在预配置中设置包含变量,但从来没有成功过。相反,我们是这样做的:

...
USE_NUMPY=${USE_NUMPY:="y"}

if [ "$USE_NUMPY" = "y" ]; then
    export NUMPY_INC_DIR=`python -c 'import numpy; print numpy.get_include()'`
fi

自从我们开始这样包含之后,就没有遇到过任何问题。

1

你可能在你的Ubuntu系统上安装了多个Python版本。为了使用EPD来安装Cantera,你需要明确告诉它要使用哪个版本:

PYTHON_CMD=${PYTHON_CMD:="/usr/local/EPD/bin/python"}

每个版本都有自己的site-packages目录,所以通过指定PYTHON_CMD,你也就指定了要使用哪个site-packages。当Numpy安装时,它还会在site-packages/numpy/core/include/numpy目录下安装与Numarray的接口,因此不需要单独下载Numarray。另外,numpy会被安装到EPDsite-packages目录中,所以NUMPY_HOME(这个变量只有在numpy没有安装在默认目录时才会用到)可以保持不变。希望这些信息对你有帮助。

1

我找到了解决办法。按照我之前遵循的这些说明,我成功了。上次我下载的是tar.gz文件,这次我用了子版本库,可能更新得更及时吧。总之,这次成功了,而且我也不需要更改默认的python命令。

补充一下:我确实需要把这个从默认值改成:

PYTHON_CMD=${PYTHON_CMD:="/usr/local/EPD/bin/python"}

我觉得把这些步骤也发出来,方便其他用户参考,是个好主意:

第一步是安装一些依赖项。这可以通过apt-get来处理: sudo apt-get install subversion g++ gfortran python2.6-dev python-numpy libsundials* graphviz
下一步是获取cantera的源代码。可以通过从cantera网站下载cantera-1.8.0-beta-tar.gz,或者从svn检查最新版本来完成: svn checkout http://cantera.googlecode.com/svn/cantera18/trunk/ cantera
进入cantera目录(无论是svn检出的还是解压后的cantera-1.8.0)
编辑名为preconfig的文件,确保以下几行被包含,可以通过注释或编辑来实现:
PYTHON_PACKAGE=${PYTHON_PACKAGE:="full"}
USE_NUMPY=${USE_NUMPY:="y"}
SUNDIALS_VERSION=${SUNDIALS_VERSION:='2.3'}

Then in a terminal run the following commands:
./preconfig
make
sudo make install
source ~/setup_cantera
If every thing went well you should be able to import the Cantera module in python:
python
>>>from Cantera import *

撰写回答