I'm using php's exec()
command to run a python script but I'm receiving the following error:
Array ( [0] => Traceback (most recent call last): [1] => File "/vagrant/SRC_Local_Website/EAF_MODEL/EAF_Model.py", line 20, in [2] => from pylab import * [3] => File "/usr/lib/pymodules/python2.7/pylab.py", line 1, in [4] => from matplotlib.pylab import * [5] => File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 774, in [6] => rcParams = rc_params() [7] =>
File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 692, in rc_params [8] => fname = matplotlib_fname() [9] => File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 604, in matplotlib_fname [10] =>
fname = os.path.join(get_configdir(), 'matplotlibrc') [11] => File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 253, in wrapper [12] => ret = func(*args, **kwargs) [13] =>
File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 478, in _get_configdir [14] => raise RuntimeError("Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"%h) [15] => RuntimeError: Failed to create /var/www/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data )
From what I understand, python is unable to find the matplotlib and pylab modules.
Some thing's I'd like to note:
- I've run:
sudo apt-get install python-numpy python-scipy python-matplotlib
successfully. - If I run this python file directly from the shell (e.g.
$python myFile.py
) the program runs fine with no errors. - In my php file I've tried to specify where these files can be found with
putenv('PYTHONPATH= ...
(see below)
For example, my imports are as follows:
from casadi import *
from numpy import *
from pylab import *
import matplotlib.pyplot as plt
Originally, cadADi couldn't be found so I added:
putenv('PYTHONPATH=$PYTHONPATH:/vagrant/SRC_Local_Website/EAF_MODEL/python_plugins/casadi-py27-np1.9.1-v3.0.0');
and that was no longer an issue.
Similarly with numpy I had to add:
putenv('PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/dist-packages');
Lastly, I tried to add:
putenv('PYTHONPATH=$PYTHONPATH:/usr/lib/pymodules/python2.7');
Which is where mathplotlib and pylab are located (I don't know why they're separated from dist-packages
, that's just where they were automatically installed to), but unfortunately I'm still receiving the error above.
Question: What could be the cause of this issue?