简体   繁体   English

在 docker 映像 python:3.9.13-alpine3.16 上使用“pip install psutil”错误:找不到 linux/ethtool.h

[英]use 'pip install psutil' on docker image python:3.9.13-alpine3.16 error: linux/ethtool.h not found

I tried to install python module psutl in docker python:3.9.13-alpine3.16我试图在 docker python:3.9.13-alpine3.16
But it reported the following mistake:但是它报告了以下错误:

Building wheels for collected packages: psutil
  Building wheel for psutil (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for psutil (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [51 lines of output]
      /tmp/tmpb62wij4i.c:1:10: fatal error: linux/ethtool.h: No such file or directory
          1 | #include <linux/ethtool.h>
            |          ^~~~~~~~~~~~~~~~~
      compilation terminated.
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-39
      creating build/lib.linux-x86_64-cpython-39/psutil
      copying psutil/__init__.py -> build/lib.linux-x86_64-cpython-39/psutil
      copying psutil/_common.py -> build/lib.linux-x86_64-cpython-39/psutil
      copying psutil/_compat.py -> build/lib.linux-x86_64-cpython-39/psutil
      copying psutil/_psaix.py -> build/lib.linux-x86_64-cpython-39/psutil
      copying psutil/_psbsd.py -> build/lib.linux-x86_64-cpython-39/psutil
      copying psutil/_pslinux.py -> build/lib.linux-x86_64-cpython-39/psutil
      copying psutil/_psosx.py -> build/lib.linux-x86_64-cpython-39/psutil
      copying psutil/_psposix.py -> build/lib.linux-x86_64-cpython-39/psutil
      copying psutil/_pssunos.py -> build/lib.linux-x86_64-cpython-39/psutil
      copying psutil/_pswindows.py -> build/lib.linux-x86_64-cpython-39/psutil
      creating build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/__init__.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/__main__.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/foo.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/runner.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_aix.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_bsd.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_connections.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_contracts.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_linux.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_memleaks.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_misc.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_osx.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_posix.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_process.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_sunos.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_system.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_testutils.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_unicode.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      copying psutil/tests/test_windows.py -> build/lib.linux-x86_64-cpython-39/psutil/tests
      running build_ext
      building 'psutil._psutil_linux' extension
      creating build/temp.linux-x86_64-cpython-39
      creating build/temp.linux-x86_64-cpython-39/psutil
      gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=591 -DPSUTIL_LINUX=1 -DPSUTIL_ETHTOOL_MISSING_TYPES=1 -I/usr/local/include/python3.9 -c psutil/_psutil_common.c -o build/temp.linux-x86_64-cpython-39/psutil/_psutil_common.o
      gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=591 -DPSUTIL_LINUX=1 -DPSUTIL_ETHTOOL_MISSING_TYPES=1 -I/usr/local/include/python3.9 -c psutil/_psutil_linux.c -o build/temp.linux-x86_64-cpython-39/psutil/_psutil_linux.o
      psutil/_psutil_linux.c:19:10: fatal error: linux/version.h: No such file or directory
         19 | #include <linux/version.h>
            |          ^~~~~~~~~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for psutil
Failed to build psutil
ERROR: Could not build wheels for psutil, which is required to install pyproject.toml-based projects

Recurrence process:复发过程:

  1. docker pull python:3.9.13-alpine3.16 docker 拉 python:3.9.13-alpine3.16
  2. docker run --name alpine-python3 -it [image-id] /bin/sh docker 运行 --name alpine-python3 -it [image-id] /bin/sh
  3. (In container)# apk add build-base (在容器中)# apk add build-base
  4. (In container)# pip install psutil (在容器中)# pip install psutil

Key Error:关键错误:
/tmp/tmpb62wij4i.c:1:10: fatal error: linux/ethtool.h: No such file or directory /tmp/tmpb62wij4i.c:1:10:致命错误:linux/ethtool.h:没有这样的文件或目录
1 | 1 | #include <linux/ethtool.h> #include <linux/ethtool.h>
| | ^~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~

psutil/_psutil_linux.c:19:10: fatal error: linux/version.h: No such file or directory psutil/_psutil_linux.c:19:10:致命错误:linux/version.h:没有这样的文件或目录
19 | 19 | #include <linux/version.h> #include <linux/version.h>
| | ^~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~
compilation terminated.编译终止。
error: command '/usr/bin/gcc' failed with exit code 1错误:命令“/usr/bin/gcc”失败,退出代码为 1

so, what do I need to pre-install in advance to fix?那么,我需要预先安装什么来修复? Thanks!谢谢!

You need to add the linux-headers package.您需要添加 linux-headers package。

apk add build-base linux-headers
python -m pip install psutil

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 `pip3 install psutil`错误-找不到存储库 - `pip3 install psutil` Error - Repository Not Found 为什么我通过 pip、python 在版本 3.9.13 和 pip 在版本 22.2.1 上安装 ffmpeg-python 错误 - Why do I install ffmpeg-python error via pip, python on version 3.9.13 and pip on version 22.2.1 在基于 Alpine Linux 的 Docker Image 中安装 pylint - Install pylint in Alpine Linux based Docker Image 无法使用 OpenSSL 1.0.2g 和 Python 2.7 在 Docker Alpine Linux 3.3 中“pip install cryptography” - Cannot "pip install cryptography" in Docker Alpine Linux 3.3 with OpenSSL 1.0.2g and Python 2.7 在 Node Alpine Docker 镜像上安装 Python3 - Install Python3 on Node Alpine Docker Image 在 alpine docker 映像中使用 asyncpg python 模块 - Use asyncpg python module in alpine docker image `pip3 install grpcio` 在 Alpine Linux 上失败 - `pip3 install grpcio` fails on Alpine Linux 如何在 Alpine Linux 上安装 Python 3.8,而不是来自 Python 基本映像 - How to install Python 3.8 on Alpine Linux not from Python base image Python Alpine 映像中的 pip 升级:错误:由于 OSError 无法安装软件包:[Errno 39] 目录不为空:&#39;urllib3&#39; - pip upgrading within the Python Alpine image: ERROR: Could not install packages due to an OSError: [Errno 39] Directory not empty: 'urllib3' 如何使用 dockerfile 在 linux docker-image 上安装 pip3 - How to install pip3 on a linux docker-image using dockerfile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM