為什麼在 Termux 中安裝 numpy 時 pip 會拋出錯誤?

為什麼在 Termux 中安裝 numpy 時 pip 會拋出錯誤?

我正在 Termux 中安裝 numpy。當我運行時pip install numpy --no-cache-dir,錯誤是:

File "/data/data/com.termux/files/usr/tmp/pip-install-ywfqxfk8/numpy_cf9d5c136bf14c7f9ce4181f190e4581/numpy/core/setup.py", line 171, in check_math_capabilities
          raise SystemError("One of the required function to build numpy is not"
      SystemError: One of the required function to build numpy is not available (the list is ['sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh', 'fabs', 'floor', 'ceil', 'sqrt', 'log10', 'log', 'exp', 'asin', 'acos', 'atan', 'fmod', 'modf', 'frexp', 'ldexp']).

有完整的輸出:https://pastebin.com/ExnbqtDc。為什麼會發生這種情況以及如何解決?


軟體包wheel和setuptools已安裝。

答案1

使用:

MATHLIB="m" pip3 install numpy

答案2

我不知道為什麼,但這也有效,對於 Termux 來說似乎更快:

LDFLAGS="-lm -lcompiler_rt" pip install cython numpy

答案3

補充一下xuziyue的答案:

簡潔版本:

你必須安裝與你的Python安裝相容的Numpy版本,檢查這裡


更長的版本:

最初我只是跑:

MATHLIB="m" pip install numpy

這成功安裝了 numpy,但讓我後來導入的時候出現很多錯誤它進入我的代碼。

運行python --version然後檢查這個桌子,然後嘗試:

MATHLIB="m" pip install numpy==1.24

這實際上讓一切都按預期工作。


僅供參考,我現在在 Android 上運行:

  • Termux 0.118.0
  • Python 3.10.4
  • 麻木 1.24

希望這可以幫助。

相關內容