2

kivy を使用して、astropy を利用する Android アプリを作成しようとしています。問題は、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_PATH行により、モジュールを正常に見つけてインポートでき_io.soます。これは、同様のアーキテクチャの問題を扱っていた別のレシピからコピーしました。しかし、配布スクリプトを実行しようとすると:

./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_PATHが、違いはありませんでした。ビルド時に適切なライブラリを見つけるためにkivyを取得するためのヒントはありますか?

4

1 に答える 1

1

失敗したインポートのバックトレースにget_numpy_include_path()は、 from が含まれていastropy_helpers/astropy_helpers/setup_helpers.pyます。numpy のソース コードを見ると、get_include()クロス コンパイル時にシステム上で動作しないため、ホスト Python 用に numpy をビルドできたとしても、正しくない値が取得されます。

numpyconfig.hnumpy インクルード パス ( などのファイルを検索する場所) を環境経由で提供できるように astropy にパッチを適用すると、これが修正されるためrecipes/patches/add_numpy_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__'):

このパッチだけでビルドしようとすると、ビルド エラーが発生するため、次の内容を含むstruct lconv2 つ目のパッチ ファイルを作成します。recipes/patches/lconv_fix.patch

--- 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;

Android デバイスのロケールに '.' 小数点として使用されますが、公式リポジトリのnumpy のパッチはこれを行うため、numpy と同じ状況で astropy は失敗します。

numpy 1.7.1 と公式リポジトリのレシピを使用すると、次prebuild_astropy()build_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
}
于 2015-02-16T00:58:20.490 に答える