I'm getting an annoying error without an apparent reason.
Here's the setup: I have a python script (Python 3.6 anaconda distribution) which is being called from Php (7.2.6) all on CentOS 7.
The PHP to Python call is via exec, and looks like this
exec("LANG='en_US.UTF8' " . "/opt/anaconda3/bin/python". " /home/my_web_user_name/public_html/my_python_script.py " . $parameters);
All works as a charm, if I call the PhP file (with the exec in it) from a terminal, simply as
php the_phpFile.php
However, when the same file is being called from the browser (the website user) I get the following error (the short version)
"/opt/anaconda3/lib/python3.6/ctypes/__init__.py",
line 273, in _reset_cache CFUNCTYPE(c_int)(lambda: None) MemoryError
and this is the full history of calls before the error occurs.
Traceback (most recent call last): File
"/home/my_web_user_name/public_html/my_python_script.py", line 8, in from
nltk.stem import PorterStemmer File "/opt/anaconda3/lib/python3.6/site-
packages/nltk/__init__.py",
line 114, in from nltk.collocations import * File
"/opt/anaconda3/lib/python3.6/site-packages/nltk/collocations.py",
line 39, in from nltk.metrics import ContingencyMeasures,
BigramAssocMeasures, TrigramAssocMeasures File
"/opt/anaconda3/lib/python3.6/site-packages/nltk/metrics/__init__.py",
line 16, in from nltk.metrics.scores import (accuracy, precision, recall,
f_measure, File "/opt/anaconda3/lib/python3.6/site-
packages/nltk/metrics/scores.py", line 18, in from scipy.stats.stats import
betai File "/opt/anaconda3/lib/python3.6/site-packages/scipy/__init__.py",
line 61, in from numpy import show_config as show_numpy_config File
"/opt/anaconda3/lib/python3.6/site-packages/numpy/__init__.py",
line 142, in from . import add_newdocs File
"/opt/anaconda3/lib/python3.6/site-packages/numpy/add_newdocs.py",
line 13, in from numpy.lib import add_newdoc File
"/opt/anaconda3/lib/python3.6/site-packages/numpy/lib/__init__.py",
line 8, in from .type_check import * File
"/opt/anaconda3/lib/python3.6/site-packages/numpy/lib/type_check.py",
line 11, in import numpy.core.numeric as _nx File
"/opt/anaconda3/lib/python3.6/site-packages/numpy/core/__init__.py",
line 35, in from . import _internal # for freeze programs File
"/opt/anaconda3/lib/python3.6/site-packages/numpy/core/_internal.py",
line 15, in import ctypes File
"/opt/anaconda3/lib/python3.6/ctypes/__init__.py",
line 538, in _reset_cache() File
"/opt/anaconda3/lib/python3.6/ctypes/__init__.py",
line 273, in _reset_cache CFUNCTYPE(c_int)(lambda: None) MemoryError
It seems clear that the error comes as a result of a call to nltk module, and indeed, if I turn it off the error disappears. On the other hand, things work fine when called from the terminal. So I think this has to do with some permissions.
In any case, I have no clue why this is happening.
Any ideas on this would be much appreciated.