Pipでuwsgiのインストールが失敗する場合の対処法

# 事象
pipにてuwsgiをインストールしようとしたところ、下記のとおり失敗した。

```
$ sudo pip install -U uwsgi
Collecting uwsgi
  Using cached uwsgi-2.0.20.tar.gz (804 kB)
Building wheels for collected packages: uwsgi
  Building wheel for uwsgi (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-97dwq_9q/uwsgi_24c3a89c34c847b9be2d2f525d846ef6/setup.py'"'"'; __file__='"'"'/tmp/pip-install-97dwq_9q/uwsgi_24c3a89c34c847b9be2d2f525d846ef6/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-2s5jjyxp
       cwd: /tmp/pip-install-97dwq_9q/uwsgi_24c3a89c34c847b9be2d2f525d846ef6/
  Complete output (121 lines):
  /usr/lib64/python3.9/distutils/dist.py:274: UserWarning: Unknown distribution option: 'descriptions'
    warnings.warn(msg)
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib
  copying uwsgidecorators.py -> build/lib
  installing to build/bdist.linux-x86_64/wheel
  running install
  using profile: buildconf/default.ini
  detected include path: ['/usr/lib/gcc/x86_64-redhat-linux/11/include', '/usr/local/include', '/usr/include']
  Patching "bin_name" to properly install_scripts dir
  detected CPU cores: 2
  configured CFLAGS: -O2 -I. -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -DUWSGI_HAS_IFADDRS -DUWSGI_LOCK_USE_MUTEX -DUWSGI_EVENT_USE_EPOLL -DUWSGI_EVENT_TIMER_USE_TIMERFD -DUWSGI_EVENT_FILEMONITOR_USE_INOTIFY -DUWSGI_VERSION="\"2.0.20\"" -DUWSGI_VERSION_BASE="2" -DUWSGI_VERSION_MAJOR="0" -DUWSGI_VERSION_MINOR="20" -DUWSGI_VERSION_REVISION="0" -DUWSGI_VERSION_CUSTOM="\"\"" -DUWSGI_YAML -DUWSGI_PLUGIN_DIR="\".\"" -DUWSGI_DECLARE_EMBEDDED_PLUGINS="UDEP(python);UDEP(gevent);UDEP(ping);UDEP(cache);UDEP(nagios);UDEP(rrdtool);UDEP(carbon);UDEP(rpc);UDEP(corerouter);UDEP(fastrouter);UDEP(http);UDEP(ugreen);UDEP(signal);UDEP(syslog);UDEP(rsyslog);UDEP(logsocket);UDEP(router_uwsgi);UDEP(router_redirect);UDEP(router_basicauth);UDEP(zergpool);UDEP(redislog);UDEP(mongodblog);UDEP(router_rewrite);UDEP(router_http);UDEP(logfile);UDEP(router_cache);UDEP(rawrouter);UDEP(router_static);UDEP(sslrouter);UDEP(spooler);UDEP(cheaper_busyness);UDEP(symcall);UDEP(transformation_tofile);UDEP(transformation_gzip);UDEP(transformation_chunked);UDEP(transformation_offload);UDEP(router_memcached);UDEP(router_redis);UDEP(router_hash);UDEP(router_expires);UDEP(router_metrics);UDEP(transformation_template);UDEP(stats_pusher_socket);" -DUWSGI_LOAD_EMBEDDED_PLUGINS="ULEP(python);ULEP(gevent);ULEP(ping);ULEP(cache);ULEP(nagios);ULEP(rrdtool);ULEP(carbon);ULEP(rpc);ULEP(corerouter);ULEP(fastrouter);ULEP(http);ULEP(ugreen);ULEP(signal);ULEP(syslog);ULEP(rsyslog);ULEP(logsocket);ULEP(router_uwsgi);ULEP(router_redirect);ULEP(router_basicauth);ULEP(zergpool);ULEP(redislog);ULEP(mongodblog);ULEP(router_rewrite);ULEP(router_http);ULEP(logfile);ULEP(router_cache);ULEP(rawrouter);ULEP(router_static);ULEP(sslrouter);ULEP(spooler);ULEP(cheaper_busyness);ULEP(symcall);ULEP(transformation_tofile);ULEP(transformation_gzip);ULEP(transformation_chunked);ULEP(transformation_offload);ULEP(router_memcached);ULEP(router_redis);ULEP(router_hash);ULEP(router_expires);ULEP(router_metrics);ULEP(transformation_template);ULEP(stats_pusher_socket);"
  *** uWSGI compiling server core ***
  [thread 1][gcc -pthread] core/utils.o
  [thread 0][gcc -pthread] core/protocol.o
  [thread 0][gcc -pthread] core/socket.o
  [thread 0][gcc -pthread] core/logging.o
  [thread 1][gcc -pthread] core/master.o
  [thread 0][gcc -pthread] core/master_utils.o
  [thread 1][gcc -pthread] core/emperor.o
  [thread 0][gcc -pthread] core/notify.o
  [thread 0][gcc -pthread] core/mule.o
  [thread 0][gcc -pthread] core/subscription.o
  [thread 1][gcc -pthread] core/stats.o
  [thread 0][gcc -pthread] core/sendfile.o
  [thread 0][gcc -pthread] core/async.o
  [thread 1][gcc -pthread] core/master_checks.o
  [thread 0][gcc -pthread] core/fifo.o
  [thread 1][gcc -pthread] core/offload.o
  [thread 0][gcc -pthread] core/io.o
  [thread 1][gcc -pthread] core/static.o
  [thread 1][gcc -pthread] core/websockets.o
  [thread 0][gcc -pthread] core/spooler.o
  [thread 1][gcc -pthread] core/snmp.o
  [thread 1][gcc -pthread] core/exceptions.o
  [thread 0][gcc -pthread] core/config.o
  [thread 1][gcc -pthread] core/setup_utils.o
  [thread 0][gcc -pthread] core/clock.o
  [thread 1][gcc -pthread] core/init.o
  [thread 0][gcc -pthread] core/buffer.o
  [thread 1][gcc -pthread] core/reader.o
  [thread 0][gcc -pthread] core/writer.o
  [thread 1][gcc -pthread] core/alarm.o
  [thread 1][gcc -pthread] core/cron.o
  [thread 0][gcc -pthread] core/hooks.o
  [thread 1][gcc -pthread] core/plugins.o
  [thread 0][gcc -pthread] core/lock.o
  [thread 1][gcc -pthread] core/cache.o
  [thread 0][gcc -pthread] core/daemons.o
  [thread 0][gcc -pthread] core/errors.o
  [thread 1][gcc -pthread] core/hash.o
  [thread 0][gcc -pthread] core/master_events.o
  [thread 0][gcc -pthread] core/chunked.o
  [thread 1][gcc -pthread] core/queue.o
  [thread 1][gcc -pthread] core/event.o
  [thread 0][gcc -pthread] core/signal.o
  [thread 1][gcc -pthread] core/strings.o
  [thread 0][gcc -pthread] core/progress.o
  [thread 0][gcc -pthread] core/timebomb.o
  [thread 0][gcc -pthread] core/ini.o
  [thread 1][gcc -pthread] core/fsmon.o
  [thread 0][gcc -pthread] core/mount.o
  [thread 1][gcc -pthread] core/metrics.o
  [thread 0][gcc -pthread] core/plugins_builder.o
  core/metrics.c: In function ‘uwsgi_metric_set_max’:
  core/metrics.c:706:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
    706 |     if (value > *um->value)
        |     ^~
  In file included from core/metrics.c:1:
  ./uwsgi.h:436:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
    436 | #define uwsgi_rwunlock(x) uwsgi.lock_ops.rwunlock(x)
        |                           ^~~~~
  core/metrics.c:708:9: note: in expansion of macro ‘uwsgi_rwunlock’
    708 |         uwsgi_rwunlock(uwsgi.metrics_lock);
        |         ^~~~~~~~~~~~~~
  core/metrics.c: In function ‘uwsgi_metric_set_min’:
  core/metrics.c:714:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
    714 |     if ((value > um->initial_value || 0) && value < *um->value)
        |     ^~
  In file included from core/metrics.c:1:
  ./uwsgi.h:436:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
    436 | #define uwsgi_rwunlock(x) uwsgi.lock_ops.rwunlock(x)
        |                           ^~~~~
  core/metrics.c:716:9: note: in expansion of macro ‘uwsgi_rwunlock’
    716 |         uwsgi_rwunlock(uwsgi.metrics_lock);
        |         ^~~~~~~~~~~~~~
  [thread 0][gcc -pthread] core/sharedarea.o
  [thread 0][gcc -pthread] core/rpc.o
  [thread 1][gcc -pthread] core/gateway.o
  [thread 0][gcc -pthread] core/loop.o
  [thread 0][gcc -pthread] core/cookie.o
  [thread 1][gcc -pthread] core/querystring.o
  [thread 0][gcc -pthread] core/rb_timers.o
  [thread 1][gcc -pthread] core/transformations.o
  [thread 0][gcc -pthread] core/uwsgi.o
  [thread 1][gcc -pthread] proto/base.o
  [thread 1][gcc -pthread] proto/uwsgi.o
  [thread 1][gcc -pthread] proto/http.o
  [thread 1][gcc -pthread] proto/fastcgi.o
  [thread 1][gcc -pthread] proto/scgi.o
  [thread 1][gcc -pthread] proto/puwsgi.o
  [thread 1][gcc -pthread] lib/linux_ns.o
  [thread 1][gcc -pthread] core/yaml.o
  [thread 0][gcc -pthread] core/dot_h.o
  [thread 0][gcc -pthread] core/config_py.o
  *** uWSGI compiling embedded plugins ***
  [thread 0][gcc -pthread] plugins/python/python_plugin.o
  [thread 1][gcc -pthread] plugins/python/pyutils.o
  In file included from plugins/python/python_plugin.c:1:
  plugins/python/uwsgi_python.h:2:10: fatal error: Python.h: No such file or directory
      2 | #include <Python.h>
        |          ^~~~~~~~~~
  compilation terminated.
  In file included from plugins/python/pyutils.c:1:
  plugins/python/uwsgi_python.h:2:10: fatal error: Python.h: No such file or directory
      2 | #include <Python.h>
        |          ^~~~~~~~~~
  compilation terminated.
  ----------------------------------------
  ERROR: Failed building wheel for uwsgi
  Running setup.py clean for uwsgi
Failed to build uwsgi
Installing collected packages: uwsgi
    Running setup.py install for uwsgi ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-97dwq_9q/uwsgi_24c3a89c34c847b9be2d2f525d846ef6/setup.py'"'"'; __file__='"'"'/tmp/pip-install-97dwq_9q/uwsgi_24c3a89c34c847b9be2d2f525d846ef6/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-94_b6xxa/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/uwsgi
         cwd: /tmp/pip-install-97dwq_9q/uwsgi_24c3a89c34c847b9be2d2f525d846ef6/
    Complete output (92 lines):
    /usr/lib64/python3.9/distutils/dist.py:274: UserWarning: Unknown distribution option: 'descriptions'
      warnings.warn(msg)
    running install
    using profile: buildconf/default.ini
    detected include path: ['/usr/lib/gcc/x86_64-redhat-linux/11/include', '/usr/local/include', '/usr/include']
    Patching "bin_name" to properly install_scripts dir
    detected CPU cores: 2
    configured CFLAGS: -O2 -I. -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -DUWSGI_HAS_IFADDRS -DUWSGI_LOCK_USE_MUTEX -DUWSGI_EVENT_USE_EPOLL -DUWSGI_EVENT_TIMER_USE_TIMERFD -DUWSGI_EVENT_FILEMONITOR_USE_INOTIFY -DUWSGI_VERSION="\"2.0.20\"" -DUWSGI_VERSION_BASE="2" -DUWSGI_VERSION_MAJOR="0" -DUWSGI_VERSION_MINOR="20" -DUWSGI_VERSION_REVISION="0" -DUWSGI_VERSION_CUSTOM="\"\"" -DUWSGI_YAML -DUWSGI_PLUGIN_DIR="\".\"" -DUWSGI_DECLARE_EMBEDDED_PLUGINS="UDEP(python);UDEP(gevent);UDEP(ping);UDEP(cache);UDEP(nagios);UDEP(rrdtool);UDEP(carbon);UDEP(rpc);UDEP(corerouter);UDEP(fastrouter);UDEP(http);UDEP(ugreen);UDEP(signal);UDEP(syslog);UDEP(rsyslog);UDEP(logsocket);UDEP(router_uwsgi);UDEP(router_redirect);UDEP(router_basicauth);UDEP(zergpool);UDEP(redislog);UDEP(mongodblog);UDEP(router_rewrite);UDEP(router_http);UDEP(logfile);UDEP(router_cache);UDEP(rawrouter);UDEP(router_static);UDEP(sslrouter);UDEP(spooler);UDEP(cheaper_busyness);UDEP(symcall);UDEP(transformation_tofile);UDEP(transformation_gzip);UDEP(transformation_chunked);UDEP(transformation_offload);UDEP(router_memcached);UDEP(router_redis);UDEP(router_hash);UDEP(router_expires);UDEP(router_metrics);UDEP(transformation_template);UDEP(stats_pusher_socket);" -DUWSGI_LOAD_EMBEDDED_PLUGINS="ULEP(python);ULEP(gevent);ULEP(ping);ULEP(cache);ULEP(nagios);ULEP(rrdtool);ULEP(carbon);ULEP(rpc);ULEP(corerouter);ULEP(fastrouter);ULEP(http);ULEP(ugreen);ULEP(signal);ULEP(syslog);ULEP(rsyslog);ULEP(logsocket);ULEP(router_uwsgi);ULEP(router_redirect);ULEP(router_basicauth);ULEP(zergpool);ULEP(redislog);ULEP(mongodblog);ULEP(router_rewrite);ULEP(router_http);ULEP(logfile);ULEP(router_cache);ULEP(rawrouter);ULEP(router_static);ULEP(sslrouter);ULEP(spooler);ULEP(cheaper_busyness);ULEP(symcall);ULEP(transformation_tofile);ULEP(transformation_gzip);ULEP(transformation_chunked);ULEP(transformation_offload);ULEP(router_memcached);ULEP(router_redis);ULEP(router_hash);ULEP(router_expires);ULEP(router_metrics);ULEP(transformation_template);ULEP(stats_pusher_socket);"
    *** uWSGI compiling server core ***
    core/utils.o is up to date
    core/protocol.o is up to date
    core/socket.o is up to date
    core/logging.o is up to date
    core/master.o is up to date
    core/master_utils.o is up to date
    core/emperor.o is up to date
    core/notify.o is up to date
    core/mule.o is up to date
    core/subscription.o is up to date
    core/stats.o is up to date
    core/sendfile.o is up to date
    core/async.o is up to date
    core/master_checks.o is up to date
    core/fifo.o is up to date
    core/offload.o is up to date
    core/io.o is up to date
    core/static.o is up to date
    core/websockets.o is up to date
    core/spooler.o is up to date
    core/snmp.o is up to date
    core/exceptions.o is up to date
    core/config.o is up to date
    core/setup_utils.o is up to date
    core/clock.o is up to date
    core/init.o is up to date
    core/buffer.o is up to date
    core/reader.o is up to date
    core/writer.o is up to date
    core/alarm.o is up to date
    core/cron.o is up to date
    core/hooks.o is up to date
    core/plugins.o is up to date
    core/lock.o is up to date
    core/cache.o is up to date
    core/daemons.o is up to date
    core/errors.o is up to date
    core/hash.o is up to date
    core/master_events.o is up to date
    core/chunked.o is up to date
    core/queue.o is up to date
    core/event.o is up to date
    core/signal.o is up to date
    core/strings.o is up to date
    core/progress.o is up to date
    core/timebomb.o is up to date
    core/ini.o is up to date
    core/fsmon.o is up to date
    core/mount.o is up to date
    core/metrics.o is up to date
    core/plugins_builder.o is up to date
    core/sharedarea.o is up to date
    core/rpc.o is up to date
    core/gateway.o is up to date
    core/loop.o is up to date
    core/cookie.o is up to date
    core/querystring.o is up to date
    core/rb_timers.o is up to date
    core/transformations.o is up to date
    core/uwsgi.o is up to date
    proto/base.o is up to date
    proto/uwsgi.o is up to date
    proto/http.o is up to date
    proto/fastcgi.o is up to date
    proto/scgi.o is up to date
    proto/puwsgi.o is up to date
    lib/linux_ns.o is up to date
    core/yaml.o is up to date
    [thread 0][gcc -pthread] core/dot_h.o
    [thread 1][gcc -pthread] core/config_py.o
    *** uWSGI compiling embedded plugins ***
    [thread 1][gcc -pthread] plugins/python/python_plugin.o
    [thread 0][gcc -pthread] plugins/python/pyutils.o
    In file included from plugins/python/python_plugin.c:1:
    plugins/python/uwsgi_python.h:2:10: fatal error: Python.h: No such file or directory
        2 | #include <Python.h>
          |          ^~~~~~~~~~
    compilation terminated.
    In file included from plugins/python/pyutils.c:1:
    plugins/python/uwsgi_python.h:2:10: fatal error: Python.h: No such file or directory
        2 | #include <Python.h>
          |          ^~~~~~~~~~
    compilation terminated.
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-97dwq_9q/uwsgi_24c3a89c34c847b9be2d2f525d846ef6/setup.py'"'"'; __file__='"'"'/tmp/pip-install-97dwq_9q/uwsgi_24c3a89c34c847b9be2d2f525d846ef6/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-94_b6xxa/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/uwsgi Check the logs for full command output.
```
## 環境
OS: Fedora release 34 (Thirty Four)
Python: Python 3.9.7
Pip: pip 21.2.4 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
Pypy3: Python 3.6.9 (da0a95678aa0, May 26 2021, 11:40:28) [PyPy 7.3.1 with GCC 11.1.1 20210428 (Red Hat 11.1.1-1)]
Pypy版Pip: pip 21.2.4 from /usr/lib64/pypy3-7.3/site-packages/pip (python 3.6)

# 解決法
python3-develをインストールしたところ、無事インストールできた。

```
# dnf install python3-devel.x86_64
メタデータの期限切れの最終確認: 0:06:03 時間前の 2021年10月10日 12時35分25秒 に実施しました。
依存関係が解決しました。
========================================================================================================================================================================
 パッケージ                                 アーキテクチャー                    バージョン                                   リポジトリー                         サイズ
========================================================================================================================================================================
インストール:
 python3-devel                              x86_64                              3.9.7-1.fc34                                 updates                              206 k

トランザクションの概要
========================================================================================================================================================================
インストール  1 パッケージ

ダウンロードサイズの合計: 206 k
インストール後のサイズ: 766 k
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
python3-devel-3.9.7-1.fc34.x86_64.rpm                                                                                                   1.1 MB/s | 206 kB     00:00    
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
合計                                                                                                                                    267 kB/s | 206 kB     00:00     
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                                                                                                1/1 
  インストール中   : python3-devel-3.9.7-1.fc34.x86_64                                                                                                              1/1 
  scriptletの実行中: python3-devel-3.9.7-1.fc34.x86_64                                                                                                              1/1 
  検証             : python3-devel-3.9.7-1.fc34.x86_64                                                                                                              1/1 

インストール済み:
  python3-devel-3.9.7-1.fc34.x86_64                                                                                                                                     

完了しました!



# pip install -U uwsgi
Collecting uwsgi
  Using cached uwsgi-2.0.20.tar.gz (804 kB)
Building wheels for collected packages: uwsgi
  Building wheel for uwsgi (setup.py) ... done
  Created wheel for uwsgi: filename=uWSGI-2.0.20-cp39-cp39-linux_x86_64.whl size=476634 sha256=207a232ca71f94c3cdc67b563a6c77f473a3d7dc2615fa64000c882811ee36a9
  Stored in directory: /root/.cache/pip/wheels/09/ac/7b/80681f729cf8c820803228c8752d49581afd6a446bc58b172c
Successfully built uwsgi
Installing collected packages: uwsgi
Successfully installed uwsgi-2.0.20
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
```
Pypy3版のPipでも同様

```
$ sudo pypy3 -m pip install -U uwsgi
Collecting uwsgi
  Using cached uwsgi-2.0.20.tar.gz (804 kB)
Building wheels for collected packages: uwsgi
  Building wheel for uwsgi (setup.py) ... done
  Created wheel for uwsgi: filename=uWSGI-2.0.20-pp36-pypy36_pp73-linux_x86_64.whl size=420283 sha256=c07c825c66de590f90aa18a56578733a0063a046ba47c734b951371d868dfecc
  Stored in directory: /root/.cache/pip/wheels/6d/02/1e/f35c561ac7e714483e4f0a6155b3a3de06e30283eb490fc7ed
Successfully built uwsgi
Installing collected packages: uwsgi
Successfully installed uwsgi-2.0.20
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
```