'Why am I getting an error while installing discord.py on mac

QUICK NOTE: This question is probably more related to macos or zsh than python.

I am trying to install discord.py on macos monterey, though I have the xcode command line tools, I am facing errors while installing discord.py. I am running Python 3.11.0a5.

The whole output:

Collecting discord.py
  Using cached discord.py-1.7.3-py3-none-any.whl (786 kB)
Collecting aiohttp<3.8.0,>=3.6.0
  Using cached aiohttp-3.7.4.post0-py3-none-any.whl
Collecting yarl<2.0,>=1.0
  Using cached yarl-1.7.2.tar.gz (168 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting async-timeout<4.0,>=3.0
  Using cached async_timeout-3.0.1-py3-none-any.whl (8.2 kB)
Collecting chardet<5.0,>=2.0
  Using cached chardet-4.0.0-py2.py3-none-any.whl (178 kB)
Collecting typing-extensions>=3.6.5
  Using cached typing_extensions-4.1.1-py3-none-any.whl (26 kB)
Collecting multidict<7.0,>=4.5
  Using cached multidict-6.0.2-cp311-cp311-macosx_10_9_universal2.whl
Collecting attrs>=17.3.0
  Using cached attrs-21.4.0-py2.py3-none-any.whl (60 kB)
Collecting idna>=2.0
  Using cached idna-3.3-py3-none-any.whl (61 kB)
Building wheels for collected packages: yarl
  Building wheel for yarl (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for yarl (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [43 lines of output]
      **********************
      * Accelerated build *
      **********************
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-universal2-3.11
      creating build/lib.macosx-10.9-universal2-3.11/yarl
      copying yarl/_url.py -> build/lib.macosx-10.9-universal2-3.11/yarl
      copying yarl/_quoting_py.py -> build/lib.macosx-10.9-universal2-3.11/yarl
      copying yarl/__init__.py -> build/lib.macosx-10.9-universal2-3.11/yarl
      copying yarl/_quoting.py -> build/lib.macosx-10.9-universal2-3.11/yarl
      running egg_info
      writing yarl.egg-info/PKG-INFO
      writing dependency_links to yarl.egg-info/dependency_links.txt
      writing requirements to yarl.egg-info/requires.txt
      writing top-level names to yarl.egg-info/top_level.txt
      reading manifest file 'yarl.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      warning: no previously-included files matching '*.pyc' found anywhere in distribution
      warning: no previously-included files matching '*.cache' found anywhere in distribution
      warning: no previously-included files found matching 'yarl/*.html'
      warning: no previously-included files found matching 'yarl/*.so'
      warning: no previously-included files found matching 'yarl/*.pyd'
      no previously-included directories found matching 'docs/_build'
      adding license file 'LICENSE'
      writing manifest file 'yarl.egg-info/SOURCES.txt'
      copying yarl/__init__.pyi -> build/lib.macosx-10.9-universal2-3.11/yarl
      copying yarl/_quoting_c.c -> build/lib.macosx-10.9-universal2-3.11/yarl
      copying yarl/_quoting_c.pyi -> build/lib.macosx-10.9-universal2-3.11/yarl
      copying yarl/_quoting_c.pyx -> build/lib.macosx-10.9-universal2-3.11/yarl
      copying yarl/py.typed -> build/lib.macosx-10.9-universal2-3.11/yarl
      running build_ext
      building 'yarl._quoting_c' extension
      creating build/temp.macosx-10.9-universal2-3.11
      creating build/temp.macosx-10.9-universal2-3.11/yarl
      clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c yarl/_quoting_c.c -o build/temp.macosx-10.9-universal2-3.11/yarl/_quoting_c.o
      yarl/_quoting_c.c:198:12: fatal error: 'longintrepr.h' file not found
        #include "longintrepr.h"
                 ^~~~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' 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 yarl
Failed to build yarl
ERROR: Could not build wheels for yarl, which is required to install pyproject.toml-based projects


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source