themattinthehatt / behavenet

Toolbox for analyzing behavioral videos and neural activity
https://behavenet.readthedocs.io/
MIT License
57 stars 15 forks source link

Problem with matplotlib backend on MacOS #6

Closed adelaneh closed 4 years ago

adelaneh commented 4 years ago

When trying to train ARHMM using the following command:

python behavenet/fitting/arhmm_grid_search.py --data_config ~/.behavenet/musall_vistrained_params.json --model_config ~/.behavenet/arhmm_model.json --training_config ~/.behavenet/arhmm_training.json --compute_config ~/.behavenet/arhmm_compute.json

the following error appears:

Traceback (most recent call last):
  File "behavenet/fitting/arhmm_grid_search.py", line 16, in <module>
    from behavenet.plotting.arhmm_utils import get_latent_arrays_by_dtype
  File "/behavenet/plotting/arhmm_utils.py", line 11, in <module>
    import matplotlib.pyplot as plt
  File "anaconda3/envs/behavenet/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2372, in <module>
    switch_backend(rcParams["backend"])
  File "anaconda3/envs/behavenet/lib/python3.7/site-packages/matplotlib/pyplot.py", line 207, in switch_backend
    backend_mod = importlib.import_module(backend_name)
  File "anaconda3/envs/behavenet/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "anaconda3/envs/behavenet/lib/python3.7/site-packages/matplotlib/backends/backend_macosx.py", line 14, in <module>
    from matplotlib.backends import _macosx
ImportError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
adelaneh commented 4 years ago

In file behavenet/plotting/arhmm_utils.py add the following two lines

import matplotlib
matplotlib.use('agg',warn=False, force=True)

before

import matplotlib.pyplot as plt

themattinthehatt commented 4 years ago

@adelaneh thanks for posting this. Do you have any idea why changing the matplotlib backend helps with this problem? The traceback seems opaque, but I would not have expected matplotlib to be involved.

adelaneh commented 4 years ago

@themattinthehatt I corrected the original comment to reflect the correct error message. I was getting multiple error messages at the time of posting this and ended up copying the wrong one here. Hope this makes it clear now.