manabuQiita
@manabuQiita (mnb)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

CentOS7にWSGIがインストールできない

解決したいこと

Django初心者です。
CentOS7にDjangoアプリケーションをデプロイするためにmod_wsgiをインストールしたいです。
しかし以下のエラーがでます。
pipのバージョンアップや関連モジュールのインポートなど調べられることはやったのですが、エラーが解消されず、エラーの意味もよく分からず困っています。
何かアドバイス頂けると幸いです。
なおCentOSはAWSのLightSailにOSのみインストールで使用しております。

発生している問題・エラー

[centos@ip-000-00-0-00 Python-3.8.5]$ pip3 install mod_wsgi
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Defaulting to user installation because normal site-packages is not writeable
Collecting mod_wsgi
  Using cached mod_wsgi-4.7.1.tar.gz (498 kB)
Using legacy 'setup.py install' for mod-wsgi, since package 'wheel' is not installed.
Installing collected packages: mod-wsgi
    Running setup.py install for mod-wsgi ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-u6vfqv01/mod-wsgi_17fc039febda49c7b1a97d0c81aefbf6/setup.py'"'"'; __file__='"'"'/tmp/pip-install-u6vfqv01/mod-wsgi_17fc039febda49c7b1a97d0c81aefbf6/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-uox0wbcw/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/centos/.local/include/python3.6m/mod-wsgi
         cwd: /tmp/pip-install-u6vfqv01/mod-wsgi_17fc039febda49c7b1a97d0c81aefbf6/
    Complete output (36 lines):
    /usr/lib64/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/mod_wsgi
    copying src/__init__.py -> build/lib.linux-x86_64-3.6/mod_wsgi
    creating build/lib.linux-x86_64-3.6/mod_wsgi/server
    copying src/server/__init__.py -> build/lib.linux-x86_64-3.6/mod_wsgi/server
    copying src/server/environ.py -> build/lib.linux-x86_64-3.6/mod_wsgi/server
    copying src/server/apxs_config.py -> build/lib.linux-x86_64-3.6/mod_wsgi/server
    creating build/lib.linux-x86_64-3.6/mod_wsgi/server/management
    copying src/server/management/__init__.py -> build/lib.linux-x86_64-3.6/mod_wsgi/server/management
    creating build/lib.linux-x86_64-3.6/mod_wsgi/server/management/commands
    copying src/server/management/commands/runmodwsgi.py -> build/lib.linux-x86_64-3.6/mod_wsgi/server/management/commands
    copying src/server/management/commands/__init__.py -> build/lib.linux-x86_64-3.6/mod_wsgi/server/management/commands
    creating build/lib.linux-x86_64-3.6/mod_wsgi/docs
    copying docs/_build/html/__init__.py -> build/lib.linux-x86_64-3.6/mod_wsgi/docs
    creating build/lib.linux-x86_64-3.6/mod_wsgi/images
    copying images/__init__.py -> build/lib.linux-x86_64-3.6/mod_wsgi/images
    copying images/snake-whiskey.jpg -> build/lib.linux-x86_64-3.6/mod_wsgi/images
    running build_ext
    building 'mod_wsgi.server.mod_wsgi-py36' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/src
    creating build/temp.linux-x86_64-3.6/src/server
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/httpd -I/usr/include/python3.6m -c src/server/wsgi_thread.c -o build/temp.linux-x86_64-3.6/src/server/wsgi_thread.o -I/usr/include/httpd -I. -I/usr/include/apr-1 -DLINUX -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -pthread -I/usr/include/apr-1 -I/usr/include/apr-1
    In file included from src/server/wsgi_thread.h:24:0,
                     from src/server/wsgi_thread.c:21:
    src/server/wsgi_python.h:24:20: fatal error: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-u6vfqv01/mod-wsgi_17fc039febda49c7b1a97d0c81aefbf6/setup.py'"'"'; __file__='"'"'/tmp/pip-install-u6vfqv01/mod-wsgi_17fc039febda49c7b1a97d0c81aefbf6/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-uox0wbcw/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/centos/.local/include/python3.6m/mod-wsgi Check the logs for full command output.
[centos@ip-000-00-0-00 Python-3.8.5]$ yum pip3 install mod_wsgi
Loaded plugins: fastestmirror
No such command: pip3. Please use /usr/bin/yum --help
[centos@ip-000-00-0-00 Python-3.8.5]$ which python3
/usr/bin/python3
[centos@ip-000-00-0-00 Python-3.8.5]$ which python
/usr/bin/python
[centos@ip-000-00-0-00 Python-3.8.5]$ which pip
/usr/local/bin/pip
[centos@ip-000-00-0-00 Python-3.8.5]$ which pip3
/usr/local/bin/pip3
[centos@ip-000-00-0-00 Python-3.8.5]$ which pip2
/usr/bin/which: no pip2 in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/var/lib/snapd/snap/bin:/home/centos/.local/bin:/home/centos/bin)
[

OSとPythonのバージョン

CentOS Linux release 7.9.2009 (Core)
$ python -V
Python 2.7.5
$ python3 -V
Python 3.6.8

自分で試したこと

以下を実行

pip3 install -U pip
sudo yum -y install httpd-devel
sudo yum -y install gcc
sudo yum -y install make
sudo yum -y install python-devel
0

2Answer

sudo yum -y install python-devel

python3を使用しているのであれば、「python-devel」ではなく「python3-devel」ではないですか?
(最近CentOSを使っていないので、パッケージ名はよくわかりませんが)

0Like

ご回答ありがとうございます。
別途教材を参考にし、CentOSではなくUbuntuで作り直したところうまくいきました。

恐らくそうだったかもしれませんが、今後同様のエラーに詰まったら参考にさせて頂きます。
ご回答ありがとうございました。

0Like

Your answer might help someone💌