在 Linux Python 3.8.5 上安装 Discord.py

Install Discord.py on a Linux Python 3.8.5

我最近在 tinker board 上安装了 armbian focal,并试图安装 discord python 包。它是 运行 预安装的 python 3.8.5 版本,但我只在 python 版本为 3.9 时看到安装 discord 包的错误。我还在 windows python 3.8.7 上成功安装了 discord 包,这意味着我不知道 windows python 3.8 和 linux python 3.8,或者我只是缺少一些包来帮助我安装 discord.py,可能是因为它是预装的(轻量级)。

我看到程序“Could not build wheels for multidict or yarl”,但我不确定如何解决这个问题。我搜索了这个问题的各种版本,但我只找到了使用 python 3.9 的人,这是一个已知错误。

这是尝试安装的完整输出,错误占了大部分。还有其他人 运行 遇到同样的问题吗?我希望获得有关如何成功安装 discord.py.

的一些指导
Collecting discord
  Using cached discord-1.0.1-py3-none-any.whl (1.1 kB)
Collecting discord.py>=1.0.1
  Using cached discord.py-1.5.1-py3-none-any.whl (701 kB)
Processing /root/.cache/pip/wheels/2d/6d/bb/486f8c893f1dcc917860a5b3e2f2ca286c398f7d548ffc649c/aiohttp-3.6.3-py3-none-any.whl
Requirement already satisfied: chardet<4.0,>=2.0 in /usr/lib/python3/dist-packages (from aiohttp<3.7.0,>=3.6.0->discord.py>=1.0.1->discord) (3.0.4)
Collecting multidict<5.0,>=4.5
  Using cached multidict-4.7.6.tar.gz (50 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting yarl<1.6.0,>=1.0
  Using cached yarl-1.5.1.tar.gz (173 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting async-timeout<4.0,>=3.0
  Using cached async_timeout-3.0.1-py3-none-any.whl (8.2 kB)
Collecting attrs>=17.3.0
  Using cached attrs-20.3.0-py2.py3-none-any.whl (49 kB)
Requirement already satisfied: idna>=2.0 in /usr/lib/python3/dist-packages (from yarl<1.6.0,>=1.0->aiohttp<3.7.0,>=3.6.0->discord.py>=1.0.1->discord) (2.8)
Building wheels for collected packages: multidict, yarl
  Building wheel for multidict (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /tmp/tmpkkp4jqll build_wheel /tmp/tmpfgkdfx0m
       cwd: /tmp/pip-install-j7e2t_uk/multidict
  Complete output (47 lines):
  **********************
  * Accellerated build *
  **********************
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-armv7l-3.8
  creating build/lib.linux-armv7l-3.8/multidict
  copying multidict/_multidict_py.py -> build/lib.linux-armv7l-3.8/multidict
  copying multidict/_multidict_base.py -> build/lib.linux-armv7l-3.8/multidict
  copying multidict/_compat.py -> build/lib.linux-armv7l-3.8/multidict
  copying multidict/_abc.py -> build/lib.linux-armv7l-3.8/multidict
  copying multidict/__init__.py -> build/lib.linux-armv7l-3.8/multidict
  running egg_info
  writing multidict.egg-info/PKG-INFO
  writing dependency_links to multidict.egg-info/dependency_links.txt
  writing top-level names to multidict.egg-info/top_level.txt
  reading manifest file 'multidict.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 found matching 'multidict/_multidict.html'
  warning: no previously-included files found matching 'multidict/*.so'
  warning: no previously-included files found matching 'multidict/*.pyd'
  warning: no previously-included files found matching 'multidict/*.pyd'
  no previously-included directories found matching 'docs/_build'
  writing manifest file 'multidict.egg-info/SOURCES.txt'
  copying multidict/__init__.pyi -> build/lib.linux-armv7l-3.8/multidict
  copying multidict/_multidict.c -> build/lib.linux-armv7l-3.8/multidict
  copying multidict/py.typed -> build/lib.linux-armv7l-3.8/multidict
  creating build/lib.linux-armv7l-3.8/multidict/_multilib
  copying multidict/_multilib/defs.h -> build/lib.linux-armv7l-3.8/multidict/_multilib
  copying multidict/_multilib/dict.h -> build/lib.linux-armv7l-3.8/multidict/_multilib
  copying multidict/_multilib/istr.h -> build/lib.linux-armv7l-3.8/multidict/_multilib
  copying multidict/_multilib/iter.h -> build/lib.linux-armv7l-3.8/multidict/_multilib
  copying multidict/_multilib/pair_list.h -> build/lib.linux-armv7l-3.8/multidict/_multilib
  copying multidict/_multilib/views.h -> build/lib.linux-armv7l-3.8/multidict/_multilib
  running build_ext
  building 'multidict._multidict' extension
  creating build/temp.linux-armv7l-3.8
  creating build/temp.linux-armv7l-3.8/multidict
  arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.8 -c multidict/_multidict.c -o build/temp.linux-armv7l-3.8/multidict/_multidict.o -O2 -std=c99 -Wall -Wsign-compare -Wconversion -fno-strict-aliasing -pedantic
  multidict/_multidict.c:1:10: fatal error: Python.h: No such file or directory
      1 | #include "Python.h"
        |          ^~~~~~~~~~
  compilation terminated.
  error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for multidict
  Building wheel for yarl (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /tmp/tmps5xafkze build_wheel /tmp/tmp_pdfqzao
       cwd: /tmp/pip-install-j7e2t_uk/yarl
  Complete output (42 lines):
  **********************
  * Accellerated build *
  **********************
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-armv7l-3.8
  creating build/lib.linux-armv7l-3.8/yarl
  copying yarl/_url.py -> build/lib.linux-armv7l-3.8/yarl
  copying yarl/_quoting_py.py -> build/lib.linux-armv7l-3.8/yarl
  copying yarl/_quoting.py -> build/lib.linux-armv7l-3.8/yarl
  copying yarl/__init__.py -> build/lib.linux-armv7l-3.8/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'
  writing manifest file 'yarl.egg-info/SOURCES.txt'
  copying yarl/__init__.pyi -> build/lib.linux-armv7l-3.8/yarl
  copying yarl/_quoting_c.c -> build/lib.linux-armv7l-3.8/yarl
  copying yarl/_quoting_c.pyi -> build/lib.linux-armv7l-3.8/yarl
  copying yarl/_quoting_c.pyx -> build/lib.linux-armv7l-3.8/yarl
  copying yarl/py.typed -> build/lib.linux-armv7l-3.8/yarl
  running build_ext
  building 'yarl._quoting_c' extension
  creating build/temp.linux-armv7l-3.8
  creating build/temp.linux-armv7l-3.8/yarl
  arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.8 -c yarl/_quoting_c.c -o build/temp.linux-armv7l-3.8/yarl/_quoting_c.o
  yarl/_quoting_c.c:4:10: fatal error: Python.h: No such file or directory
      4 | #include "Python.h"
        |          ^~~~~~~~~~
  compilation terminated.
  error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for yarl
Failed to build multidict yarl
ERROR: Could not build wheels for multidict, yarl which use PEP 517 and cannot be installed directly```

原来我缺少 python3-dev 包,它不包含在 armbian 的预装 python.

要安装 python3-dev 软件包,只需 运行:

sudo apt install python3-dev

感谢@CoderCharmander