Solved! RHEL 8 Python3 VENV Mod_WSGI <Python.h> compilation terminated error command /usr/bin/gcc failed with exit code 1
Hello:
After a long bumpy road of one WSGI solution after another, I am trying to get Apache HTTPd and Mod_WSGI installed for my Django project. After looking through the open and closed issues for missing Python.h headers, they all seems to be ubuntu/Debian environments. Both
pip3 install --target=/home/djangoweb/env/lib64/python3.11/site-packages mod_wsgi
and
pip3 install mod_wsgi
Fail to install due to python.h headers missing. But Python3-devel packages were installed. I also tried to delete the env directory after installing python3-devel packages.
Below are the packages and steps I took to attempt to get the solution setup for RHEL 8 VM standalone.
Environment:
RHEL 8 VM Apache HTTPD 2.4.37 Python 3 Django 5.1
whereis python3
python3: /home/djangoweb/env/bin/python3.11 /home/djangoweb/env/bin/python3
apachectl -v
Server version: Apache/2.4.37 (Red Hat Enterprise Linux)
Server built: Aug 7 2024 11:33:03
(env) [django@server01 ~]$ pip3 install mod_wsgi
Collecting pipenv
Using cached pipenv-2024.0.1-py3-none-any.whl.metadata (19 kB)
Collecting mod_wsgi
Using cached mod_wsgi-5.0.0.tar.gz (497 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting wheel
Using cached wheel-0.44.0-py3-none-any.whl.metadata (2.3 kB)
Collecting certifi (from pipenv)
Using cached certifi-2024.7.4-py3-none-any.whl.metadata (2.2 kB)
Collecting setuptools>=67 (from pipenv)
Using cached setuptools-72.2.0-py3-none-any.whl.metadata (6.6 kB)
Collecting virtualenv>=20.24.2 (from pipenv)
Using cached virtualenv-20.26.3-py3-none-any.whl.metadata (4.5 kB)
Collecting distlib<1,>=0.3.7 (from virtualenv>=20.24.2->pipenv)
Using cached distlib-0.3.8-py2.py3-none-any.whl.metadata (5.1 kB)
Collecting filelock<4,>=3.12.2 (from virtualenv>=20.24.2->pipenv)
Using cached filelock-3.15.4-py3-none-any.whl.metadata (2.9 kB)
Collecting platformdirs<5,>=3.9.1 (from virtualenv>=20.24.2->pipenv)
Using cached platformdirs-4.2.2-py3-none-any.whl.metadata (11 kB)
Using cached pipenv-2024.0.1-py3-none-any.whl (3.2 MB)
Using cached wheel-0.44.0-py3-none-any.whl (67 kB)
Using cached setuptools-72.2.0-py3-none-any.whl (2.3 MB)
Using cached virtualenv-20.26.3-py3-none-any.whl (5.7 MB)
Using cached certifi-2024.7.4-py3-none-any.whl (162 kB)
Using cached distlib-0.3.8-py2.py3-none-any.whl (468 kB)
Using cached filelock-3.15.4-py3-none-any.whl (16 kB)
Using cached platformdirs-4.2.2-py3-none-any.whl (18 kB)
Building wheels for collected packages: mod_wsgi
Building wheel for mod_wsgi (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for mod_wsgi (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [33 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-311
creating build/lib.linux-x86_64-cpython-311/mod_wsgi
copying src/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi
creating build/lib.linux-x86_64-cpython-311/mod_wsgi/server
copying src/server/apxs_config.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server
copying src/server/environ.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server
copying src/server/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server
creating build/lib.linux-x86_64-cpython-311/mod_wsgi/server/management
copying src/server/management/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server/management
creating build/lib.linux-x86_64-cpython-311/mod_wsgi/server/management/commands
copying src/server/management/commands/runmodwsgi.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server/management/commands
copying src/server/management/commands/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server/management/commands
creating build/lib.linux-x86_64-cpython-311/mod_wsgi/docs
copying docs/_build/html/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/docs
creating build/lib.linux-x86_64-cpython-311/mod_wsgi/images
copying images/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/images
copying images/snake-whiskey.jpg -> build/lib.linux-x86_64-cpython-311/mod_wsgi/images
running build_ext
building 'mod_wsgi.server.mod_wsgi-py311' extension
creating build/temp.linux-x86_64-cpython-311
creating build/temp.linux-x86_64-cpython-311/src
creating build/temp.linux-x86_64-cpython-311/src/server
gcc -pthread -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/httpd -I/home/djangoweb/env/include -I/usr/include/python3.11 -c src/server/mod_wsgi.c -o build/temp.linux-x86_64-cpython-311/src/server/mod_wsgi.o -I/usr/include/httpd -I. -I/usr/include/apr-1 -DLINUX -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -pthread -I/usr/include/apr-1 -I/usr/include/apr-1
In file included from src/server/mod_wsgi.c:22:
src/server/wsgi_python.h:26:10: fatal error: Python.h: No such file or directory
#include <Python.h>
^~~~~~~~~~
compilation terminated.
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 mod_wsgi
Failed to build mod_wsgi
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (mod_wsgi)
(env) [django@server01 ~]$ pip3 install --target=/home/djangoweb/env/lib64/python3.11/site-packages mod_wsgi
Collecting mod_wsgi
Using cached mod_wsgi-5.0.0.tar.gz (497 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: mod_wsgi
Building wheel for mod_wsgi (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [33 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-311
creating build/lib.linux-x86_64-cpython-311/mod_wsgi
copying src/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi
creating build/lib.linux-x86_64-cpython-311/mod_wsgi/server
copying src/server/apxs_config.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server
copying src/server/environ.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server
copying src/server/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server
creating build/lib.linux-x86_64-cpython-311/mod_wsgi/server/management
copying src/server/management/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server/management
creating build/lib.linux-x86_64-cpython-311/mod_wsgi/server/management/commands
copying src/server/management/commands/runmodwsgi.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server/management/commands
copying src/server/management/commands/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/server/management/commands
creating build/lib.linux-x86_64-cpython-311/mod_wsgi/docs
copying docs/_build/html/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/docs
creating build/lib.linux-x86_64-cpython-311/mod_wsgi/images
copying images/__init__.py -> build/lib.linux-x86_64-cpython-311/mod_wsgi/images
copying images/snake-whiskey.jpg -> build/lib.linux-x86_64-cpython-311/mod_wsgi/images
running build_ext
building 'mod_wsgi.server.mod_wsgi-py311' extension
creating build/temp.linux-x86_64-cpython-311
creating build/temp.linux-x86_64-cpython-311/src
creating build/temp.linux-x86_64-cpython-311/src/server
gcc -pthread -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/httpd -I/home/djangoweb/env/include -I/usr/include/python3.11 -c src/server/mod_wsgi.c -o build/temp.linux-x86_64-cpython-311/src/server/mod_wsgi.o -I/usr/include/httpd -I. -I/usr/include/apr-1 -DLINUX -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -pthread -I/usr/include/apr-1 -I/usr/include/apr-1
In file included from src/server/mod_wsgi.c:22:
src/server/wsgi_python.h:26:10: fatal error: Python.h: No such file or directory
#include <Python.h>
^~~~~~~~~~
compilation terminated.
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 mod_wsgi
Running setup.py clean for mod_wsgi
Failed to build mod_wsgi
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (mod_wsgi)
pip3 list
Package Version
------------ --------
certifi 2024.7.4
distlib 0.3.8
filelock 3.15.4
pip 24.2
pipenv 2024.0.1
platformdirs 4.2.2
setuptools 72.2.0
virtualenv 20.26.3
wheel 0.44.0
(env) [django@server01 ~]$ python -c 'import sys; print(sys.prefix)'
/home/djangoweb/env
pip3 install --upgrade pip
pip3 install pipenv mod_wsgi wheel
sudo yum -y install httpd httpd-devel
/usr/sbin/httpd -M | grep wsgi_mod
wsgi_module (shared)
RedHat Customer Portal Article
Getting "fatal error: Python.h: No such file or directory" while installing python packages using pip3.
Resolution RPM python3-devel provides pyhton.h header files and the dependent libraries.
sudo dnf install python3-devel
Updating Subscription Management repositories.
Last metadata expiration check: 2:31:07 ago on Sat 17 Aug 2024 09:16:05 PM EDT.
Package python36-devel-3.6.8-39.module+el8.10.0+20784+edafcd43.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
Redhat Customer Portal Article
How to install mod_wsgi module in RHEL 8 and later
Resolution The mod_wsgi package was replaced in RHEL 8 for python3-mod_wsgi.
The mod_wsgi module for the Apache HTTP Server has been updated to Python 3. WSGI applications are now supported only with Python 3
sudo dnf install python3-mod_wsgi
Updating Subscription Management repositories.
Last metadata expiration check: 2:58:44 ago on Sat 17 Aug 2024 09:16:05 PM EDT.
Package python3-mod_wsgi-4.6.4-5.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
Is this just meant to be for the benefit of others, or are you expecting help on something? Post is a bit confusing.
Why would I make a post title with an error? I am trying to resolve the missing Python.h missing headers.
Because you posted what is the normal solution, which is to install the python3-devel package.
What is in the /usr/include/python3.11 directory on your system after having installed that package?
(env) [django@server01 ~]$ ls -la /usr/include/python3.11
total 68
drwxr-xr-x 2 root root 4096 Jul 31 16:39 .
drwxr-xr-x. 59 root root 12288 Aug 18 00:35 ..
-rw-r--r-- 1 root root 53193 Jun 19 09:53 pyconfig-64.h
According to RHEL docs:
- https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/configuring_basic_system_settings/installing-and-using-dynamic-programming-languages_configuring-basic-system-settings#con_python-versions_assembly_introduction-to-python
you possibly should be trying to install python3.11-devel and not python3-devel.
Thank you for the help. It seems I thought I had the base and extras EPEL repos enabled, but I did not. Once enabling them, I was about to find the package.
cat /etc/yum.repos.d/epel.repo
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 8 - $basearch - Debug
[epel-source]
name=Extra Packages for Enterprise Linux 8 - $basearch - Source
sudo yum update
sudo yum install python3.11-devel
Installing:
python3.11-devel x86_64 3.11.9-2.el8_10 rhel-8-for-x86_64-appstream-rpms 248 k
pip3 install mod_wsgi
Collecting mod_wsgi
Using cached mod_wsgi-5.0.0.tar.gz (497 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: mod_wsgi
Building wheel for mod_wsgi (setup.py) ... done
Created wheel for mod_wsgi: filename=mod_wsgi-5.0.0-cp311-cp311-linux_x86_64.whl size=822033 sha256=e3b8a183066058b242945bdd77788b7756fdce98dda0a366f23dab6c217da328
Stored in directory: /home/djangoweb/.cache/pip/wheels/ce/41/92/c1ed5e7fdd0de5efa61e07ab3cca40deeaa53a0b140a068b17
Successfully built mod_wsgi
Installing collected packages: mod_wsgi
Successfully installed mod_wsgi-5.0.0
pip3 install --target=/home/djangoweb/env/lib64/python3.11/site-packages mod_wsgi
Collecting mod_wsgi
Using cached mod_wsgi-5.0.0-cp311-cp311-linux_x86_64.whl
Installing collected packages: mod_wsgi
Successfully installed mod_wsgi-5.0.0
WARNING: Target directory /home/djangoweb/env/lib64/python3.11/site-packages/mod_wsgi already exists. Specify --upgrade to force replacement.
WARNING: Target directory /home/djangoweb/env/lib64/python3.11/site-packages/mod_wsgi-5.0.0.dist-info already exists. Specify --upgrade to force replacement.