如何为kivy android安装编译astropy(使用numpy)?

如何为kivy android安装编译astropy(使用numpy)?,android,python,numpy,kivy,astropy,Android,Python,Numpy,Kivy,Astropy,我正在尝试使用kivy创建一个android应用程序,该应用程序使用astropy。困难在于astropy在安装过程中使用了numpy,我还没能让它成功加载numpy库。我相信问题在于它正在寻找为ARM体系结构编译的库——如何让它在构建时找到正确的库 我正在使用kivy提供的linux虚拟机。numpy配方本身效果很好。对于astropy,我创建了一个recipe.sh脚本,除了标准设置之外,还包含以下构建函数: function build_astropy() { cd $BUILD_

我正在尝试使用kivy创建一个android应用程序,该应用程序使用astropy。困难在于astropy在安装过程中使用了numpy,我还没能让它成功加载numpy库。我相信问题在于它正在寻找为ARM体系结构编译的库——如何让它在构建时找到正确的库

我正在使用kivy提供的linux虚拟机。numpy配方本身效果很好。对于astropy,我创建了一个
recipe.sh
脚本,除了标准设置之外,还包含以下构建函数:

function build_astropy() {
    cd $BUILD_astropy
    export BUILDLIB_PATH="$BUILD_hostpython/build/lib.linux-`uname -m`-2.7/"
    export PYTHONPATH=$SITEPACKAGES_PATH:$BUILDLIB_PATH
    push_arm
    try $HOSTPYTHON setup.py install
    pop_arm
}
BUILDLIB\u路径
行允许它成功地找到并导入
\u io。因此
模块-我从另一个处理类似架构问题的配方中复制了它。但当我尝试运行distribute脚本时:

./distribute.sh -f -m "astropy kivy" -d astropy
它试图导入numpy,但出现以下错误:

ImportError: /home/kivy/android/python-for-android/build/python-install/lib/python2.7/site-packages/numpy/core/multiarray.so: cannot open shared object file: No such file or directory
该文件确实存在,但可能是为ARM编译的。我尝试添加本地numpy安装:

/usr/lib/python2.7/dist-packages/numpy/core/

BUILDLIB\u路径
,但没有任何区别。是否有人有任何关于让kivy在构建时找到正确库的技巧?

导入失败的回溯包含
get\u numpy\u include\u path()
,它来自
astropy\u helpers/astropy\u helpers/setup\u helpers.py
。查看numpy的
get_include()
的源代码,交叉编译时它在系统上不起作用,因此即使您为宿主Python构建了numpy,它也会得到不正确的值

修补astropy以允许通过环境提供的numpy include路径(在其中查找文件,如
numpyconfig.h
)将解决此问题,因此创建包含以下内容的
recipes/patches/add\u numpy\u include.patch

--- astropy-0.4.4.orig/astropy_helpers/astropy_helpers/setup_helpers.py 2015-02-15 18:16:02.135642283 -0600
+++ astropy-0.4.4/astropy_helpers/astropy_helpers/setup_helpers.py  2015-02-15 18:15:10.985674250 -0600
@@ -1307,6 +1307,11 @@
     # install, since Numpy may still think it's in "setup mode", when
     # in fact we're ready to use it to build astropy now.

+    # Allow the environment to override the include path, to allow
+    # cross-compilation
+    if 'NUMPY_INCLUDE_PATH' in os.environ:
+        return os.environ['NUMPY_INCLUDE_PATH']
+
     if sys.version_info[0] >= 3:
         import builtins
         if hasattr(builtins, '__NUMPY_SETUP__'):
--- astropy-0.4.4.orig/cextern/wcslib/C/wcsutil.c   2015-02-15 18:07:46.549935299 -0600
+++ astropy-0.4.4/cextern/wcslib/C/wcsutil.c    2015-02-15 18:36:07.062452345 -0600
@@ -247,7 +247,7 @@

 {
   struct lconv *locale_data = localeconv();
-  const char *decimal_point = locale_data->decimal_point;
+  const char *decimal_point = ".";

   if (decimal_point[0] != '.' || decimal_point[1] != 0) {
     size_t decimal_point_len = strlen(decimal_point);
@@ -311,7 +311,7 @@

 {
   struct lconv *locale_data = localeconv();
-  const char *decimal_point = locale_data->decimal_point;
+  const char *decimal_point = ".";

   if (decimal_point[0] != '.' || decimal_point[1] != 0) {
     char *out = outbuf;
--- astropy-0.4.4.orig/cextern/cfitsio/fitscore.c   2015-02-15 18:07:46.553935299 -0600
+++ astropy-0.4.4/cextern/cfitsio/fitscore.c    2015-02-15 18:41:16.626440539 -0600
@@ -9226,7 +9226,7 @@

     if (!decimalpt) { /* only do this once for efficiency */
        lcc = localeconv();   /* set structure containing local decimal point symbol */
-       decimalpt = *(lcc->decimal_point);
+       decimalpt = '.';
     }

     errno = 0;
@@ -9296,7 +9296,7 @@

     if (!decimalpt) { /* only do this once for efficiency */
        lcc = localeconv();   /* set structure containing local decimal point symbol */
-       decimalpt = *(lcc->decimal_point);
+       decimalpt = '.';
     }

     errno = 0;
如果仅使用此修补程序进行构建,则会导致关于
struct lconv
的构建错误,因此请创建第二个修补程序文件
recipes/patches/lconv\u fix.patch
,其中包含以下内容:

--- astropy-0.4.4.orig/astropy_helpers/astropy_helpers/setup_helpers.py 2015-02-15 18:16:02.135642283 -0600
+++ astropy-0.4.4/astropy_helpers/astropy_helpers/setup_helpers.py  2015-02-15 18:15:10.985674250 -0600
@@ -1307,6 +1307,11 @@
     # install, since Numpy may still think it's in "setup mode", when
     # in fact we're ready to use it to build astropy now.

+    # Allow the environment to override the include path, to allow
+    # cross-compilation
+    if 'NUMPY_INCLUDE_PATH' in os.environ:
+        return os.environ['NUMPY_INCLUDE_PATH']
+
     if sys.version_info[0] >= 3:
         import builtins
         if hasattr(builtins, '__NUMPY_SETUP__'):
--- astropy-0.4.4.orig/cextern/wcslib/C/wcsutil.c   2015-02-15 18:07:46.549935299 -0600
+++ astropy-0.4.4/cextern/wcslib/C/wcsutil.c    2015-02-15 18:36:07.062452345 -0600
@@ -247,7 +247,7 @@

 {
   struct lconv *locale_data = localeconv();
-  const char *decimal_point = locale_data->decimal_point;
+  const char *decimal_point = ".";

   if (decimal_point[0] != '.' || decimal_point[1] != 0) {
     size_t decimal_point_len = strlen(decimal_point);
@@ -311,7 +311,7 @@

 {
   struct lconv *locale_data = localeconv();
-  const char *decimal_point = locale_data->decimal_point;
+  const char *decimal_point = ".";

   if (decimal_point[0] != '.' || decimal_point[1] != 0) {
     char *out = outbuf;
--- astropy-0.4.4.orig/cextern/cfitsio/fitscore.c   2015-02-15 18:07:46.553935299 -0600
+++ astropy-0.4.4/cextern/cfitsio/fitscore.c    2015-02-15 18:41:16.626440539 -0600
@@ -9226,7 +9226,7 @@

     if (!decimalpt) { /* only do this once for efficiency */
        lcc = localeconv();   /* set structure containing local decimal point symbol */
-       decimalpt = *(lcc->decimal_point);
+       decimalpt = '.';
     }

     errno = 0;
@@ -9296,7 +9296,7 @@

     if (!decimalpt) { /* only do this once for efficiency */
        lcc = localeconv();   /* set structure containing local decimal point symbol */
-       decimalpt = *(lcc->decimal_point);
+       decimalpt = '.';
     }

     errno = 0;
lconv修复程序并不是一个很好的修复程序,因为它假设Android设备上的区域设置使用“.”作为十进制分隔符,但官方存储库中的会这样做,因此astropy将在与numpy相同的情况下失败

使用numpy 1.7.1和按照的配方,以下
prebuild\u astropy()
build\u astropy()
函数适用于astropy 0.4.4,调用
/distribute.sh-m“numpy astropy kivy”-d astropy

function prebuild_astropy() {
    cd $BUILD_astropy

    if [ -f .patched ]; then
        return
    fi

    try patch -p1 < $RECIPE_astropy/patches/add_numpy_include.patch
    try patch -p1 < $RECIPE_astropy/patches/lconv_fix.patch
    touch .patched
    true
}

function build_astropy() {
    cd $BUILD_astropy
    export BUILDLIB_PATH="$BUILD_hostpython/build/lib.linux-`uname -m`-2.7/"
    export PYTHONPATH=$SITEPACKAGES_PATH:$BUILDLIB_PATH
    export NUMPY_INCLUDE_PATH="$BUILD_PATH/python-install/lib/python2.7/site-packages/numpy/core/include"
    push_arm
    try $BUILD_PATH/python-install/bin/python.host setup.py install
    pop_arm
    unset BUILDLIB_PATH
    unset PYTHONPATH
    unset NUMPY_INCLUDE_PATH
}
函数预构建_astropy(){
cd$BUILD\u astropy
如果[-f.修补];则
返回
fi
尝试补丁-p1<$RECIPE\u astropy/patches/add\u numpy\u include.patch
尝试修补程序-p1<$RECIPE\u astropy/patches/lconv\u fix.patch
触摸,修补
真的
}
函数构建_astropy(){
cd$BUILD\u astropy
export BUILDLIB_PATH=“$BUILD_hostpython/BUILD/lib.linux-`uname-m`-2.7/”
导出PYTHONPATH=$SITEPACKAGES\u路径:$BUILDLIB\u路径
export NUMPY_INCLUDE_PATH=“$BUILD_PATH/python安装/lib/python2.7/site packages/NUMPY/core/INCLUDE”
推臂
请尝试$BUILD\u PATH/python install/bin/python.host setup.py install
弹臂
取消设置BUILDLIB_路径
未固定蟒蛇
取消设置NUMPY\u包含路径
}

以前没有关于为
android
编译
numpy
的问题吗?正常的
linux
安装使用了许多额外的
C
库(甚至还有Fortran编译器)。我对kivy一无所知,但听起来你的
$PYTHONPATH
@hpaulj上可能有一些愚蠢的东西。为android编译numpy的步骤很好。我的问题是astropy需要导入linux编译的numpy来构建,我不知道如何让它找到正确的库。那么你能在Android设备上运行
numpy
numpy
。因此
文件必须链接到Android代码,而不是linux代码。是的,当我进行单独的numpy分发时:
/distribute.sh-f-m“numpy kivy”-d numpy
工作正常,并且numpy在Android设备上运行。奇怪的是
lcc->decimal\u点在该平台上不起作用。为什么呢?我想知道这些补丁的某些形式是否值得包含在Astropy中(后者没有那么多,除非它使用某种ifdef)。