giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.32k stars 1.39k forks source link

[Asahi Fedora] Building from source fails on Linux ARM64 #2293

Open JoelHBierman opened 1 year ago

JoelHBierman commented 1 year ago

Summary

Description

Running the commands given in the install instructions:

sudo yum install gcc python3-devel
pip install --no-binary :all: psutil

fails with trackback:

Collecting psutil
  Using cached psutil-5.9.5.tar.gz (493 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
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
  ╰─> [45 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-aarch64-cpython-39
      creating build/lib.linux-aarch64-cpython-39/psutil
      copying psutil/_pswindows.py -> build/lib.linux-aarch64-cpython-39/psutil
      copying psutil/_pssunos.py -> build/lib.linux-aarch64-cpython-39/psutil
      copying psutil/_psposix.py -> build/lib.linux-aarch64-cpython-39/psutil
      copying psutil/_psosx.py -> build/lib.linux-aarch64-cpython-39/psutil
      copying psutil/_pslinux.py -> build/lib.linux-aarch64-cpython-39/psutil
      copying psutil/_psbsd.py -> build/lib.linux-aarch64-cpython-39/psutil
      copying psutil/_psaix.py -> build/lib.linux-aarch64-cpython-39/psutil
      copying psutil/_compat.py -> build/lib.linux-aarch64-cpython-39/psutil
      copying psutil/_common.py -> build/lib.linux-aarch64-cpython-39/psutil
      copying psutil/__init__.py -> build/lib.linux-aarch64-cpython-39/psutil
      creating build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_windows.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_unicode.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_testutils.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_system.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_sunos.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_process.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_posix.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_osx.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_misc.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_memleaks.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_linux.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_contracts.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_connections.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_bsd.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/test_aix.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/runner.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/__main__.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      copying psutil/tests/__init__.py -> build/lib.linux-aarch64-cpython-39/psutil/tests
      running build_ext
      building 'psutil._psutil_linux' extension
      creating build/temp.linux-aarch64-cpython-39
      creating build/temp.linux-aarch64-cpython-39/psutil
      gcc -pthread -B /home/joel/miniconda3/envs/Qiskit-0420-esm-010-nature-045/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -Wall -fPIC -O2 -n1 .2-a+fp16+rcpc+dotprod+crypto -isystem /home/joel/miniconda3/envs/Qiskit-0420-esm-010-nature-045/include -I/home/joel/miniconda3/envs/Qiskit-0420-esm-010-nature-045/include -fPIC -O2 -n1 .2-a+fp16+rcpc+dotprod+crypto -isystem /home/joel/miniconda3/envs/Qiskit-0420-esm-010-nature-045/include -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=595 -DPy_LIMITED_API=0x03060000 -DPSUTIL_LINUX=1 -I/home/joel/miniconda3/envs/Qiskit-0420-esm-010-nature-045/include/python3.9 -c psutil/_psutil_common.c -o build/temp.linux-aarch64-cpython-39/psutil/_psutil_common.o
      gcc: error: unrecognized command-line option ‘-n1’; did you mean ‘-n’?
      gcc: error: unrecognized command-line option ‘-n1’; did you mean ‘-n’?
      psutil could not be installed from sources. Perhaps Python header files are not installed. Try running:
        sudo yum install gcc python3-devel
      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
ben9923 commented 1 year ago

You forgot to mention you're using Miniconda... Old Python 3.9 Miniconda versions have corrupt CFLAGS configuration for arm64 that's causing binary extension builds to break.

You said you're using 3.9.6, which is quite old. Seems like versions up to Python 3.9.12 shipping with Miniconda 4.12.0 is broken, so you'd want something newer than that (22.11.1-1 or newer).

Upgrade to the latest 3.9 release and try again, I believe it should fix it for you :)

To reproduce:

docker run --rm -it --init --platform linux/arm64 fedora:38

# In container:
dnf install -y gcc
cd /tmp
curl -O https://repo.anaconda.com/miniconda/Miniconda3-py39_4.12.0-Linux-aarch64.sh
chmod +x Miniconda3-py39_4.12.0-Linux-aarch64.sh && ./Miniconda3-py39_4.12.0-Linux-aarch64.sh
# Install with default settings

. /root/miniconda3/bin/activate
pip install psutil
fc0712 commented 1 year ago

Hey im having a similar issue, when building docker container using GitHub actions:

I get the following error:

 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=596 -DPy_LIMITED_API=0x03060000 -DPSUTIL_ETHTOOL_MISSING_TYPES=1 -DPSUTIL_LINUX=1 -I/usr/local/include/python3.9 -c psutil/_psutil_common.c -o build/temp.linux-aarch64-cpython-39/psutil/_psutil_common.o
#14 166.7       psutil could not be installed from sources because gcc is not installed. Try running:
#14 166.7         sudo apt-get install gcc python3-dev
#14 166.7       error: command 'gcc' failed: No such file or directory
#14 166.7       [end of output]

UPDATE:

I ended up just installing python3 dev and gcc in my docker image:

RUN apt-get update && apt-get -y install gcc python3-dev