geoai-lab / PyGRF

GNU General Public License v3.0
8 stars 1 forks source link

ModuleNotFoundError due to an ESDA dependency on Matplotlib #1

Closed Tadusko closed 1 month ago

Tadusko commented 1 month ago

Hi! Thank you for an interesting package and work.

I installed the package in a new venv. However, it throws a ModuleNotFoundError when trying to import PyGRF due to matplotlib missing. More specifically, it seems Moran function in ESDA is from matplotlib import colors. Matplotlib seems to be an optional dependency for ESDA, which is perhaps why it is not installed here.

Installing matplotlib fixes the error and the rest of the notebook ran smoothly.

Below is the error dump:


ModuleNotFoundError Traceback (most recent call last) Cell In[1], line 6 3 from sklearn.model_selection import train_test_split, KFold 4 from sklearn.metrics import mean_squared_error, r2_score ----> 6 import PyGRF

File ~/pygrf/lib/python3.12/site-packages/PyGRF/init.py:1 ----> 1 from .PyGRF import PyGRFBuilder 2 from .PyGRF import search_bandwidth 3 from .PyGRF import search_bw_lw_ISA

File ~/pygrf/lib/python3.12/site-packages/PyGRF/PyGRF.py:8 6 from scipy.spatial import distance 7 import libpysal ----> 8 from esda import Moran 11 class PyGRFBuilder: 12 """ 13 Python implementation of geographic random forest (PyGRF). 14 (...) 44 More details please refer to the documentation of scikit-learn at the link: https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html. 45 """

File ~/pygrf/lib/python3.12/site-packages/esda/init.py:29 21 from .losh import LOSH # noqa F401 22 from .map_comparison import ( 23 areal_entropy, 24 completeness, # noqa F401 (...) 27 overlay_entropy, 28 ) ---> 29 from .moran import ( 30 Moran, 31 Moran_BV, 32 Moran_BV_matrix, 33 Moran_Local, # noqa F401 34 Moran_Local_BV, 35 Moran_Local_Rate, 36 Moran_Rate, 37 ) 38 from .silhouettes import boundary_silhouette, path_silhouette # noqa F401 39 from .smaup import Smaup # noqa F401

File ~/pygrf/lib/python3.12/site-packages/esda/moran.py:19 17 from libpysal.weights import W 18 from libpysal.weights.spatial_lag import lag_spatial ---> 19 from matplotlib import colors 20 from scipy import sparse 22 from .crand import _prepare_univariate

ModuleNotFoundError: No module named 'matplotlib'

sunkai-8304 commented 1 month ago

Hi, thank you so much for your interest in our work.

I have tried again with a totally new virtual environment. PyGRF can be installed and imported successfully without Matplotlib. I also looked into the file moran.py and did not see such a line of code: from matplotlib import colors. Could you be more specific with the issue you ran into? I am not sure whether it is because of different package versions.

Thanks, Kai

Tadusko commented 1 month ago

Hi Kai and thanks for the response!

I looked into it a bit and it seems that matplotlib was added to moran.py in the latest version, 2.6. It's in the current source – more specifically, it seems there's a new function called_explore_local_moran where the colors are used (the diffs are here.

I installed pygrf in a fresh venv and then started running one of the example notebooks. My Python version is 3.12 and the ESDA version installed with pygrf is 2.6. Maybe this makes a difference?

sunkai-8304 commented 1 month ago

Hi Tatu,

Thank you so much for checking this problem! I also looked into it again. It is indeed because of the new version of ESDA 2.6, which requires Matplotlib as a dependency. I have added a section "Potential issues and solutions" on the GitHub repository page to explain a bit about this issue in case other researchers may also run into this problem.

Thanks again for pointing out this issue! Please let us know if you have any further questions or there are any new issues with this package.

Kai