Bug 2418294 - Numpy importing error in mod_wsgi app
Summary: Numpy importing error in mod_wsgi app
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: mod_wsgi
Version: 43
Hardware: x86_64
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Luboš Uhliarik
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2025-12-02 12:40 UTC by Clodoaldo Pinto Neto
Modified: 2025-12-02 12:40 UTC (History)
3 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Clodoaldo Pinto Neto 2025-12-02 12:40:52 UTC
I'm getting an error when importing `numpy` from an Apache mod_wsgi application on Fedora 43 and 42. It does not happen in Rocky Linux 9, the production server.

app.wsgi:

import sys
sys.path.insert(0, '/var/www/html/test/')
from test import application

test.py:

import numpy

def application(environ, start_response):
	status = '200 OK'
	output = b'Hello World!'

	response_headers = [('Content-type', 'text/plain'),
							('Content-Length', str(len(output)))]
	start_response(status, response_headers)

	return [output]

Error log:

mod_wsgi (pid=187553): Failed to exec Python script file '/var/www/html/test/app.wsgi'.
mod_wsgi (pid=187553): Exception occurred processing WSGI script '/var/www/html/test/app.wsgi'.
Traceback (most recent call last):
  File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/_core/__init__.py", line 22, in <module>
    from . import multiarray
  File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/_core/multiarray.py", line 11, in <module>
    from . import _multiarray_umath, overrides
ImportError: /var/www/html/test/venv/lib64/python3.14/site-packages/numpy/_core/_multiarray_umath.cpython-314-x86_64-linux-gnu.so: failed to map segment from shared object

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/__init__.py", line 112, in <module>
    from numpy.__config__ import show_config
  File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/__config__.py", line 4, in <module>
    from numpy._core._multiarray_umath import (
    ...<3 lines>...
    )
  File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/_core/__init__.py", line 48, in <module>
    raise ImportError(msg) from exc
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.14 from "/var/www/html/test/venv/bin/python"
  * The NumPy version is: "2.3.5"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: /var/www/html/test/venv/lib64/python3.14/site-packages/numpy/_core/_multiarray_umath.cpython-314-x86_64-linux-gnu.so: failed to map segment from shared object


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/www/html/test/app.wsgi", line 3, in <module>
    from test import application
  File "/var/www/html/test/test.py", line 1, in <module>
    import numpy
  File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/__init__.py", line 117, in <module>
    raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python interpreter from there.

If I import requests it works. Apache site config file setting the virtual environment:

<VirtualHost *:80>

    ServerName test.local
    ErrorLog logs/test-error_log
    CustomLog logs/test-access_log combined

    WSGIScriptAlias / /var/www/html/test/app.wsgi
    WSGIDaemonProcess test processes=2 threads=15 display-name=%{GROUP} python-home=/var/www/html/test/venv
    WSGIProcessGroup test

    <Directory /var/www/htm/test>
        Require all granted
    </Directory>

</VirtualHost>

When I change the above config to not set the `python-home` variable, thus using the system environment, the error changes to

mod_wsgi (pid=189076): Failed to exec Python script file '/var/www/html/test/app.wsgi'.
mod_wsgi (pid=189076): Exception occurred processing WSGI script '/var/www/html/test/app.wsgi'.
Traceback (most recent call last):
  File "/var/www/html/test/app.wsgi", line 3, in <module>
    from test import application
  File "/var/www/html/test/test.py", line 1, in <module>
    import numpy
  File "/usr/local/lib64/python3.14/site-packages/numpy/__init__.py", line 112, in <module>
    from numpy.__config__ import show_config
  File "/usr/local/lib64/python3.14/site-packages/numpy/__config__.py", line 4, in <module>
    from numpy._core._multiarray_umath import (
    ...<3 lines>...
    )
  File "/usr/local/lib64/python3.14/site-packages/numpy/_core/__init__.py", line 22, in <module>
    from . import multiarray
  File "/usr/local/lib64/python3.14/site-packages/numpy/_core/multiarray.py", line 11, in <module>
    from . import _multiarray_umath, overrides
RuntimeError: CPU dispatcher tracer already initlized

Importing `numpy` from both the `venv` and the system (as root) command line interpreter works

(venv) cpn@d3:/var/www/html/test$ python
Python 3.14.0 (main, Oct 17 2025, 00:00:00) [GCC 15.2.1 20251022 (Red Hat 15.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> 

root@d3:/etc/httpd/conf.d# python
Python 3.14.0 (main, Oct 17 2025, 00:00:00) [GCC 15.2.1 20251022 (Red Hat 15.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> 


Reproducible: Always


Note You need to log in before you can comment on or make changes to this bug.