github操作错误缺少依赖项,即使它已经从requirements.txt安装了

问题描述 投票:0回答:1

我正在运行一个 github actions,它会抛出一个关于缺少

matplotlib
包的错误,即使它已经作为requirements.txt 文件的依赖项安装了。

name: install and run test package

on: [push]

jobs:
  build:

    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest] 
        python-version: ["3.11"]
        
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          # pip install -e .
      - name: Test with pytest
        run: |
          pytest

输出:

Collecting matplotlib (from -r requirements.txt (line 3))
  Downloading matplotlib-3.8.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (5.8 kB)
Collecting lightkurve==2.4.1 (from -r requirements.txt (line 4))
  Downloading lightkurve-2.4.1-py3-none-any.whl.metadata (6.0 kB)
Collecting numpy==1.23 (from -r requirements.txt (line 5))
  Downloading numpy-1.23.0.tar.gz (10.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.7/10.7 MB 87.8 MB/s eta 0:00:00
  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'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
Collecting transitleastsquares==1.0.31 (from -r requirements.txt (line 6))
  Downloading transitleastsquares-1.0.31-py3-none-any.whl.metadata (5.4 kB)
Collecting wotan==1.10 (from -r requirements.txt (line 7))
  Downloading wotan-1.10-py3-none-any.whl.metadata (11 kB)
Collecting aesthetic==0.6 (from -r requirements.txt (line 8))
  Downloading aesthetic-0.6.tar.gz (474 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 474.2/474.2 kB 52.7 MB/s eta 0:00:00
  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 'error'
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [20 lines of output]
      Traceback (most recent call last):
        File "/opt/hostedtoolcache/Python/3.11.8/x64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/opt/hostedtoolcache/Python/3.11.8/x64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/opt/hostedtoolcache/Python/3.11.8/x64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-gjzfg86r/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-gjzfg86r/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-gjzfg86r/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 487, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/tmp/pip-build-env-gjzfg86r/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 13, in <module>
      ModuleNotFoundError: No module named 'matplotlib'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

这是requirements.txt 文件:

pre-commit==3.4.0
matplotlib
lightkurve==2.4.1
numpy==1.23
transitleastsquares==1.0.31
wotan==1.10
aesthetic==0.6
flammkuchen==1.0.3
reproject==0.12.0
astroplan==0.9
python continuous-integration github-actions python-packaging
1个回答
0
投票

看起来

aesthetic==0.6
在其
setup.py
顶部附近有以下内容。

import matplotlib

美学/setup.py

这意味着需要在构建

matplotlib
之前安装
aesthetic

引发您所显示错误的代码发生在

pip install

正在下载+构建
但尚未安装软件包时。即使您在需求中列出了 matplotlib
,在 
pip
 尝试构建 
aesthetic
 时,
matplotlib
 实际上尚未 
安装 可导入

要在不对

aesthetic

 进行任何更改的情况下完成此操作,您必须首先确保 
matplotlib
 已安装在环境中。

例如,像这样:

- name: Install dependencies run: | python -m pip install --upgrade pip pip install matplotlib pip install -r requirements.txt
    
© www.soinside.com 2019 - 2024. All rights reserved.