Armadilloフォーラム

X1でPython3モジュールインストール時エラー

tsato

2023年8月21日 13時16分

お世話になります。

Armadillo-X1(メモリ512MB)でOSがdebian9のシステムですが、
こちらにPython3をインストールして、続けてnumpyやpandasモジュールをpip3にてインストールしようとしたところ、エラーが発生してインストール出来ませんでした。(過去には出来ていたような気がしたのですが・・・)
以下、numpyをインストールのエラー表示です。(初回と2回目以降で若干違ってますが2回目以降の方です)

root@armadillo:~# sudo pip3 install numpy
Collecting numpy
  Using cached https://files.pythonhosted.org/packages/01/1b/d3ddcabd5817be02df0e6ee20d64f77ff6d0d97f83b77f65e98c8a651981/numpy-1.18.5.zip
Building wheels for collected packages: numpy
  Running setup.py bdist_wheel for numpy ... error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-i4qtitqi/numpy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmphxb076rrpip-wheel- --python-tag cp35:
  Running from numpy source directory.
  Cythonizing sources
  warning: _generator.pyx:3330:8: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: /tmp/pip-build-i4qtitqi/numpy/numpy/__init__.pxd:17:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: /tmp/pip-build-i4qtitqi/numpy/numpy/__init__.pxd:17:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: /tmp/pip-build-i4qtitqi/numpy/numpy/__init__.pxd:17:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: _philox.pyx:19:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: /tmp/pip-build-i4qtitqi/numpy/numpy/__init__.pxd:17:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
 
  Error compiling Cython file:
  ------------------------------------------------------------
  ...
              self.rng_state.ctr.v[i] = counter[i]
 
          self._reset_state_variables()
 
          self._bitgen.state = <void *>&self.rng_state
          self._bitgen.next_uint64 = &philox_uint64
                                     ^
  ------------------------------------------------------------
 
  _philox.pyx:195:35: Cannot assign type 'uint64_t (*)(void *) except? -1 nogil' to 'uint64_t (*)(void *) noexcept nogil'
  Processing numpy/random/_bounded_integers.pxd.in
  Processing numpy/random/_generator.pyx
  Processing numpy/random/_common.pyx
  Processing numpy/random/mtrand.pyx
  Processing numpy/random/_philox.pyx
  Traceback (most recent call last):
    File "/tmp/pip-build-i4qtitqi/numpy/tools/cythonize.py", line 238, in <module>
      main()
    File "/tmp/pip-build-i4qtitqi/numpy/tools/cythonize.py", line 234, in main
      find_process_files(root_dir)
    File "/tmp/pip-build-i4qtitqi/numpy/tools/cythonize.py", line 225, in find_process_files
      process(root_dir, fromfile, tofile, function, hash_db)
    File "/tmp/pip-build-i4qtitqi/numpy/tools/cythonize.py", line 191, in process
      processor_function(fromfile, tofile)
    File "/tmp/pip-build-i4qtitqi/numpy/tools/cythonize.py", line 81, in process_pyx
      [sys.executable, '-m', 'cython'] + flags + ["-o", tofile, fromfile])
    File "/usr/lib/python3.5/subprocess.py", line 271, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'cython', '-3', '--fast-fail', '-o', '_philox.c', '_philox.pyx']' returned non-zero exit status 1
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-build-i4qtitqi/numpy/setup.py", line 488, in <module>
      setup_package()
    File "/tmp/pip-build-i4qtitqi/numpy/setup.py", line 469, in setup_package
      generate_cython()
    File "/tmp/pip-build-i4qtitqi/numpy/setup.py", line 275, in generate_cython
      raise RuntimeError("Running cythonize failed!")
  RuntimeError: Running cythonize failed!
 
  ----------------------------------------
  Failed building wheel for numpy
  Running setup.py clean for numpy
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-i4qtitqi/numpy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" clean --all:
  Running from numpy source directory.
 
  `setup.py clean` is not supported, use one of the following instead:
 
    - `git clean -xdf` (cleans all files)
    - `git clean -Xdf` (cleans all versioned files, doesn't touch
                        files that aren't checked into the git repo)
 
  Add `--force` to your command to use it anyway if you must (unsupported).
 
 
  ----------------------------------------
  Failed cleaning build dir for numpy
Failed to build numpy
Installing collected packages: numpy
  Running setup.py install for numpy ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-i4qtitqi/numpy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-h6udytpy-record/install-record.txt --single-version-externally-managed --compile:
    Running from numpy source directory.
 
    Note: if you need reliable uninstall behavior, then install
    with pip instead of using `setup.py install`:
 
      - `pip install .`       (from a git repo or downloaded source
                               release)
      - `pip install numpy`   (last NumPy release on PyPi)
 
 
    Cythonizing sources
    warning: _philox.pyx:19:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
    warning: /tmp/pip-build-i4qtitqi/numpy/numpy/__init__.pxd:17:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
 
    Error compiling Cython file:
    ------------------------------------------------------------
    ...
                self.rng_state.ctr.v[i] = counter[i]
 
            self._reset_state_variables()
 
            self._bitgen.state = <void *>&self.rng_state
            self._bitgen.next_uint64 = &philox_uint64
                                       ^
    ------------------------------------------------------------
 
    _philox.pyx:195:35: Cannot assign type 'uint64_t (*)(void *) except? -1 nogil' to 'uint64_t (*)(void *) noexcept nogil'
    numpy/random/_bounded_integers.pxd.in has not changed
    numpy/random/_generator.pyx has not changed
    numpy/random/_common.pyx has not changed
    numpy/random/mtrand.pyx has not changed
    Processing numpy/random/_philox.pyx
    Traceback (most recent call last):
      File "/tmp/pip-build-i4qtitqi/numpy/tools/cythonize.py", line 238, in <module>
        main()
      File "/tmp/pip-build-i4qtitqi/numpy/tools/cythonize.py", line 234, in main
        find_process_files(root_dir)
      File "/tmp/pip-build-i4qtitqi/numpy/tools/cythonize.py", line 225, in find_process_files
        process(root_dir, fromfile, tofile, function, hash_db)
      File "/tmp/pip-build-i4qtitqi/numpy/tools/cythonize.py", line 191, in process
        processor_function(fromfile, tofile)
      File "/tmp/pip-build-i4qtitqi/numpy/tools/cythonize.py", line 81, in process_pyx
        [sys.executable, '-m', 'cython'] + flags + ["-o", tofile, fromfile])
      File "/usr/lib/python3.5/subprocess.py", line 271, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'cython', '-3', '--fast-fail', '-o', '_philox.c', '_philox.pyx']' returned non-zero exit status 1
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-i4qtitqi/numpy/setup.py", line 488, in <module>
        setup_package()
      File "/tmp/pip-build-i4qtitqi/numpy/setup.py", line 469, in setup_package
        generate_cython()
      File "/tmp/pip-build-i4qtitqi/numpy/setup.py", line 275, in generate_cython
        raise RuntimeError("Running cythonize failed!")
    RuntimeError: Running cythonize failed!
 
    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-i4qtitqi/numpy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-h6udytpy-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-i4qtitqi/numpy/

debian10のファイルシステムアーカイブの端末でも駄目でした。
他のLinuxディストリビューションでは試せてないですが、Windowsでは問題なく出来ました。
何か原因は分かりますでしょうか。
因みにエラー内容からCython関係かと思いCython(3.0.0)は問題なくインストールできましたがやはりnumpyは駄目でした。

よろしくお願いします。

コメント

at_ohsawa

2023年8月21日 16時25分

> お世話になります。
>
> Armadillo-X1(メモリ512MB)でOSがdebian9のシステムですが、
> こちらにPython3をインストールして、続けてnumpyやpandasモジュールをpip3にてインストールしようとしたところ、エラーが発生してインストール出来ませんでした。(過去には出来ていたような気がしたのですが・・・)

過去のインストールはapt-get install python3-numpyでインストールしていませんでしたか?
これなら特に問題なくインストールできます。また、新規で開発するのであれば、debian 10にしたほうが良いです。

tsato

2023年8月21日 16時42分

お世話になります。

ご回答ありがとうございます。
こちらでも調べていて原因が見えてきました。
まずdebian10では、ご教授のとおりpip3を使わず"apt-get install python3-numpy"の指令にてモジュールがインストールできました。
debian9ではやはりインストールできませんでした。調べると、公式debianリポジトリから"stretch"ディレクトリが削除されてたためでした。
(debian9のLTSサポートが今年6月に終了していたため)
とりあえずリポジトリリストの/etc/apt/sources.listの参照先ディレクトリ名をstretch→oldoldstable(debian10のものですが)に変更したら、updateが出来、pythonモジュールも形上はインストールできました。(まだ動作確認は出来ていません)

根本原因として、debian9がLTSサポート終了している以上は継続開発の基盤としてはdebian10への移行を検討した方が良い、ということになりました。

ありがとうございました。

at_ohsawa

2023年8月21日 17時05分

> とりあえずリポジトリリストの/etc/apt/sources.listの参照先ディレクトリ名をstretch→oldoldstable(debian10のものですが)に変更したら、updateが出来、pythonモジュールも形上はインストールできました。(まだ動作確認は出来ていません)

現在のoldoldstableの実体はbuster(debian 10)なので、もしstretch(debian 9)の状態から
source.listだけ書き換えると、他のライブラリとの依存関係が壊れるので
OSの完全なアップグレードが必要です。完全にアップデートするのであればapt-get dist-upgradeする必要があります。

ただ、armadilloで実行すると遅いので、運用中中でなければ、最初からdebian10 busterのユーザーランドアーカイブを
配っているので、そっちを使ったほうが速いです。

https://armadillo.atmark-techno.com/resources/software/armadillo-x1/use…
ユーザーランドだけ入れ替えるのが面倒であれば、いっそ全て消してしまうインストールディスクもあります。
https://armadillo.atmark-techno.com/resources/software/armadillo-x1/dis…

dist-upgradeで完全にアップデートしないまま、numpyをインストールすると、numpyが内部で
Cモジュールを使っているため、それがdebian9とdebian10とではlibc等周囲のライブラリのバージョン
と不整合となり実行時にエラーします。

このあたり、完全に把握していないのであれば、↑のインストールディスクでのクリーンインストールをオススメします。

ちなみに、余談ですが最初のビルドエラーについてはCythonが新しすぎるせいですね。
この時代のpythonに合わせてpipで入るnumpyのバージョンも調整されて古いものが
来ますが、numpyのwheelが要求するCythonのバージョンが不定(versionを特定しない)
ので最新の3.0.0を使おうとします。が、3.0.0だと、この時代のnumpyバージョンに対しては
エラーチェックが厳しすぎてビルドに失敗するため、敢えて古いCythonを入れてpipを使わずに
ビルドするとビルドが成功します。
が、そんな面倒なことはせずにaptでインストールすると良いと思います。

tsato

2023年8月24日 9時06分

お世話になります。

アドバイスありがとうございました。
やはり無理矢理インストールしたdebian9のものは動作が怪しそうみたいですので、
御社提供のdebian10アーカイブをベースにシステムを作り直す方向で進めます。
(運用中debian9システムとは一旦互換を切る方向にします)

よろしくお願いします。