Matplotlib package error
Closed this issue · 1 comments
Problem
The Matplotlib package must be installed apart of pyRothC, otherwise it fails.
E.g. we install pyRothC and try to use the RothC
object ourselves:
pip install pyRothC
ipython
...
In [1]: from pyRothC import RothC
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from pyRothC import RothC
File ~/.virtualenvs/playground/lib/python3.11/site-packages/pyRothC/RothC.py:12
10 from scipy.integrate import odeint
11 from scipy.interpolate import interp1d
---> 12 import matplotlib.pyplot as plt
15 class RothC:
16 """Class for Python version of The Rothamsted carbon model (RothC) 26.3."""
ModuleNotFoundError: No module named 'matplotlib'
This happens because the test lives in the same file as the code, RothC.py
.
Reasoning
We should not need Matplotlib to use the RothC
class but Matplotlib gets imported at the beginning of the file, hence this error.
Specially, it's important to avoid the usage of libraries that are not critical for the base operation expected from the package, so it can be used in different environments than just a Jupyter notebook with a whole desktop/UI suite installed. In my personal case, I do need the computations done by the RothC class on a variety of random inputs, but I don't need at all any graphics or plots being drawn because the computations are run in batches in a server and the results will go to a database - they will be visualized later from there in another systems, not necessarily using Matplotlib or even Python libraries.