Ошибка импорта Numpy в приложении mod_wsgi в Fedora 43Apache

Ответить
Anonymous
 Ошибка импорта Numpy в приложении mod_wsgi в Fedora 43

Сообщение Anonymous »

Я получаю сообщение об ошибке при импорте numpy из приложения Apache mod_wsgi в Fedora 43. Этого не происходит в Rocky Linux 9, рабочем сервере.

Код: Выделить всё

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]
Журнал ошибок:

Код: Выделить всё

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 
from . import multiarray
File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/_core/multiarray.py", line 11, in 
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 
from numpy.__config__ import show_config
File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/__config__.py", line 4, in 
from numpy._core._multiarray_umath import (
......
)
File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/_core/__init__.py", line 48, in 
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 
from test import application
File "/var/www/html/test/test.py", line 1, in 
import numpy
File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/__init__.py", line 117, in 
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.
mod_wsgi (pid=187552): Failed to exec Python script file '/var/www/html/test/app.wsgi'.
mod_wsgi (pid=187552): 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 
from . import multiarray
File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/_core/multiarray.py", line 11, in 
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 
from numpy.__config__ import show_config
File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/__config__.py", line 4, in 
from numpy._core._multiarray_umath import (
......
)
File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/_core/__init__.py", line 48, in 
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 
from test import application
File "/var/www/html/test/test.py", line 1, in 
import numpy
File "/var/www/html/test/venv/lib64/python3.14/site-packages/numpy/__init__.py", line 117, in 
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.
Если я импортирую запросы, это работает. Файл конфигурации сайта Apache, настраивающий виртуальную среду:

Код: Выделить всё


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


Require all granted



Когда я изменяю приведенную выше конфигурацию, чтобы не устанавливать переменную python-home и не использовать виртуальную среду, ошибка меняется на

Код: Выделить всё

mod_wsgi (pid=189077): Failed to exec Python script file '/var/www/html/test/app.wsgi'.
mod_wsgi (pid=189077): 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 
from test import application
File "/var/www/html/test/test.py", line 1, in 
import numpy
File "/usr/local/lib64/python3.14/site-packages/numpy/__init__.py", line 112, in 
from numpy.__config__ import show_config
File "/usr/local/lib64/python3.14/site-packages/numpy/__config__.py", line 4, in 
from numpy._core._multiarray_umath import (
......
)
File "/usr/local/lib64/python3.14/site-packages/numpy/_core/__init__.py", line 22, in 
from . import multiarray
File "/usr/local/lib64/python3.14/site-packages/numpy/_core/multiarray.py", line 11, in 
from .  import _multiarray_umath, overrides
RuntimeError: CPU dispatcher tracer already initlized
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 
from test import application
File "/var/www/html/test/test.py", line 1, in 
import numpy
File "/usr/local/lib64/python3.14/site-packages/numpy/__init__.py", line 112, in 
from numpy.__config__ import show_config
File "/usr/local/lib64/python3.14/site-packages/numpy/__config__.py", line 4, in 
from numpy._core._multiarray_umath import (
......
)
File "/usr/local/lib64/python3.14/site-packages/numpy/_core/__init__.py", line 22, in 
from . import multiarray
File "/usr/local/lib64/python3.14/site-packages/numpy/_core/multiarray.py", line 11, in 
from . import _multiarray_umath, overrides
RuntimeError: CPU dispatcher tracer already initlized
Импорт numpy как из venv, так и из системного (от имени root) интерпретатора командной строки работает

Код: Выделить всё

(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
>>>
Есть идеи?


Подробнее здесь: https://stackoverflow.com/questions/798 ... -fedora-43
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Apache»