Xserverのvenvでpipエラーを即解決|yfinanceがインストールできない

技術系

Xserverのvenvでpipエラーを即解決する方法を備忘録として残しておきます。

実行コマンド

借りているサーバ上で、venvを使用したpython環境を構築しています。
そこで以下を実行。

pip install yfinance

結果

Collecting yfinance
  Using cached yfinance-0.2.66-py2.py3-none-any.whl.metadata (6.0 kB)
Collecting pandas>=1.3.0 (from yfinance)
  Using cached pandas-2.3.3.tar.gz (4.5 MB)
  Installing build dependencies ... error
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [52 lines of output]
      Collecting meson-python>=0.13.1
        Using cached meson_python-0.18.0-py3-none-any.whl.metadata (2.8 kB)
      Collecting meson<2,>=1.2.1
        Using cached meson-1.9.1-py3-none-any.whl.metadata (1.8 kB)
      Collecting wheel
        Using cached wheel-0.45.1-py3-none-any.whl.metadata (2.3 kB)
      Collecting Cython<4.0.0a0
        Using cached cython-3.1.5-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.metadata (4.3 kB)
      Collecting numpy>=2.0
        Using cached numpy-2.3.4.tar.gz (20.6 MB)
        Installing build dependencies: started
        Installing build dependencies: finished with status 'done'
        Getting requirements to build wheel: started
        Getting requirements to build wheel: finished with status 'done'
        Installing backend dependencies: started
        Installing backend dependencies: finished with status 'done'
        Preparing metadata (pyproject.toml): started
        Preparing metadata (pyproject.toml): finished with status 'error'
        error: subprocess-exited-with-error

        × Preparing metadata (pyproject.toml) did not run successfully.
        │ exit code: 1
        ╰─> [19 lines of output]
            + /home/ryo830st/venv/bin/python3 /tmp/pip-install-9v0kken4/numpy_2ad4383a8f044c30881d648df4575d21/vendored-meson/meson/meson.py setup /tmp/pip-install-9v0kken4/numpy_2ad4383a8f044c30881d648df4575d21 /tmp/pip-install-9v0kken4/numpy_2ad4383a8f044c30881d648df4575d21/.mesonpy-hueo9ec_ -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=/tmp/pip-install-9v0kken4/numpy_2ad4383a8f044c30881d648df4575d21/.mesonpy-hueo9ec_/meson-python-native-file.ini
            The Meson build system
            Version: 1.8.3
            Source dir: /tmp/pip-install-9v0kken4/numpy_2ad4383a8f044c30881d648df4575d21
            Build dir: /tmp/pip-install-9v0kken4/numpy_2ad4383a8f044c30881d648df4575d21/.mesonpy-hueo9ec_
            Build type: native build
            Project name: NumPy
            Project version: 2.3.4
            C compiler for the host machine: cc (gcc 4.8.5 "cc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)")
            C linker for the host machine: cc ld.bfd 2.27-44
            C++ compiler for the host machine: c++ (gcc 4.8.5 "c++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)")
            C++ linker for the host machine: c++ ld.bfd 2.27-44
            Cython compiler for the host machine: cython (cython 3.1.5)
            Host machine cpu family: x86_64
            Host machine cpu: x86_64

            ../meson.build:28:4: ERROR: Problem encountered: NumPy requires GCC >= 9.3

            A full log can be found at /tmp/pip-install-9v0kken4/numpy_2ad4383a8f044c30881d648df4575d21/.mesonpy-hueo9ec_/meson-logs/meson-log.txt
            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
      error: metadata-generation-failed

      × Encountered error while generating package metadata.
      ╰─> See above for output.

      note: This is an issue with the package mentioned above, not pip.
      hint: See above for details.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

めっちゃエラー出る。

解決方法

このエラーの本質は以下でした。

ERROR: Problem encountered: NumPy requires GCC >= 9.3

使用している環境のCGGが、gcc 4.8.5 (Red Hat 4.8.5-44)。

Python 3.11 を使っているが GCC が古すぎて NumPy 2.x をビルドできない 状態です。
NumPy 2.x は GCC 9.3 以上が必要とのことです。

そのため、gcc4.8.5の身の丈に合ったNumPyをインストールします。
幸いにも、yfinanceはNumPy 1.x 系で十分動作します。
以下のように NumPy を1系に固定 してから yfinance をインストールすればOKです。

pip install "numpy<2.0" "pandas<2.2" yfinance

pythonのバージョンとかの話は少しめんどくさいですが、参考になれば。

スポンサーリンク
タイトルとURLをコピーしました