Search code examples
pythonapachenumpyflaskwsgi

Python: numpy: Interpreter change detected - this module can only be loaded into one interpreter per process


I have a flask app running on Ubuntu 18.04, Apache server, react frontend, Flask (selenium) back end.

My App runs fine but sometimes I get the following message on muy server:

numpy: Interpreter change detected - this module can only be loaded into one interpreter per process.

Complete error log:

mod_wsgi (pid=27625): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'.
[Tue Sep 15 05:01:05.669296 2020] [wsgi:error] [pid 27625:tid 140687123134208] [client 209.17.96.82:41300] Traceback (most recent call last):
[Tue Sep 15 05:01:05.669407 2020] [wsgi:error] [pid 27625:tid 140687123134208] [client 209.17.96.82:41300]   File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>
[Tue Sep 15 05:01:05.669451 2020] [wsgi:error] [pid 27625:tid 140687123134208] [client 209.17.96.82:41300]     from FlaskApp import app as application
[Tue Sep 15 05:01:05.669497 2020] [wsgi:error] [pid 27625:tid 140687123134208] [client 209.17.96.82:41300]   File "/var/www/FlaskApp/FlaskApp/__init__.py", line 5, in <module>
[Tue Sep 15 05:01:05.669538 2020] [wsgi:error] [pid 27625:tid 140687123134208] [client 209.17.96.82:41300]     import pandas as pd
[Tue Sep 15 05:01:05.669585 2020] [wsgi:error] [pid 27625:tid 140687123134208] [client 209.17.96.82:41300]   File "/usr/local/lib/python3.6/dist-packages/pandas/__init__.py", line 17, in <module>
[Tue Sep 15 05:01:05.669624 2020] [wsgi:error] [pid 27625:tid 140687123134208] [client 209.17.96.82:41300]     "Unable to import required dependencies:\\n" + "\\n".join(missing_dependencies)
[Tue Sep 15 05:01:05.669677 2020] [wsgi:error] [pid 27625:tid 140687123134208] [client 209.17.96.82:41300] ImportError: Unable to import required dependencies:
[Tue Sep 15 05:01:05.669718 2020] [wsgi:error] [pid 27625:tid 140687123134208] [client 209.17.96.82:41300] numpy: Interpreter change detected - this module can only be loaded into one interpreter per process.

I have no idea what is going on or what I should change. I read something about updating ini file to use single interpreter.

single-interpreter = true

But Im not sure if this applies to my app since im using wsgi and this is for uswgi?


Solution

  • Try adding WSGIApplicationGroup %{GLOBAL} in your .conf file. (in my case "nano /etc/apache2/sites-available/FlaskApp.conf")