Comments (11)
Thank you for the detailed investigation! Taking a look now. :)
from spinalcordtoolbox.
I tried to checkout an older version of SCT (I wanted to specifically checkout 6.3, but ran into #4524, so I ended up randomly picking 8f2b0e0, which was before the introduction of LazyImport):
I still observe an error, so in the end this issue is likely not related to the LazyImports:
Terminal output
👉 PROCESSING: sub-MGH
Traceback (most recent call last):
File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_label_utils.py", line 24, in <module>
from spinalcordtoolbox.reports.qc import generate_qc
File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/reports/qc.py", line 22, in <module>
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 1270, in <module>
rcParams['backend'] = os.environ.get('MPLBACKEND')
File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 738, in __setitem__
raise ValueError(f"Key {key}: {ve}") from None
ValueError: Key backend: 'module://matplotlib_inline.backend_inline' is not a valid value for backend; supported values are ['gtk3agg', 'gtk3cairo', 'gtk4agg', 'gtk4cairo', 'macosx', 'nbagg', 'notebook', 'qtagg', 'qtcairo', 'qt5agg', 'qt5cairo', 'tkagg', 'tkcairo', 'webagg', 'wx', 'wxagg', 'wxcairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
Traceback (most recent call last):
File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_register_multimodal.py", line 34, in <module>
from spinalcordtoolbox.reports import qc2
File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/reports/qc2.py", line 20, in <module>
from matplotlib.axes import Axes
File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 1270, in <module>
rcParams['backend'] = os.environ.get('MPLBACKEND')
File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 738, in __setitem__
raise ValueError(f"Key {key}: {ve}") from None
ValueError: Key backend: 'module://matplotlib_inline.backend_inline' is not a valid value for backend; supported values are ['gtk3agg', 'gtk3cairo', 'gtk4agg', 'gtk4cairo', 'macosx', 'nbagg', 'notebook', 'qtagg', 'qtcairo', 'qt5agg', 'qt5cairo', 'tkagg', 'tkcairo', 'webagg', 'wx', 'wxagg', 'wxcairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
Next suspicion: the declaration of %matplotlib inline
in the notebook.
from spinalcordtoolbox.
I removed the declaration %matplotlib inline
, but I still get the same error.
Googling around:
- matplotlib/matplotlib#19848
- ipython/ipython#14368
- https://stackoverflow.com/questions/59123880/valueerror-unrecognized-backend-string-gtkagg-valid-strings-are-gtk3agg
- Particularly relevant, MPL doc: https://matplotlib.org/stable/users/explain/figure/backends.html
I manually set: %matplotlib notebook
(as suggested in MPL doc), but I still get the same error. My suspicion is that inside SCT's sct_register_multimodal
, we re-set MPL's backend.
from spinalcordtoolbox.
When I comment out this line, the notebook runs without error:
Which suggests that one solution (probably not the best...) would consist in not running this line if QC report is not asked for.
from spinalcordtoolbox.
What I find strange, however, is how come we're only seeing this issue now... we've been using notebooks in other projects lately, and it included sct_register_multimodal
, example here
from spinalcordtoolbox.
Hum, it's getting weirder-- if I run another sct_register_multimodal
syntax (with other data and parameters), there is no crash:
from spinalcordtoolbox.
Ah! Interesting! When commenting out the SCT's call that comes before the call to sct_register_multimodal
, there is no crash either:
OK, so... maybe running sct_label_utils
somehow changes something about the state of MPL backend???
Nevermind... now it works even if I put back the sct_label_utils line...
from spinalcordtoolbox.
re-starting the notebook, re-running the cells, now it works without crash... i don't understand.
AH! ok, nevermind.. I had forgotten that I commented out the problematic import in sct_register_multimodal... ok starting the experiments again...
from spinalcordtoolbox.
ok, crash is consistent:
from spinalcordtoolbox.
also consistent when running it in ANOTHER notebook (the rf-shimming one):
from spinalcordtoolbox.
Briefly looking at issues in other repos, I see a few things:
module://matplotlib_inline.backend_inline
should be a valid backend.- However, 2 other people are reporting this same error (1, 2), and their reports are relatively recent (18-19 days ago). This seems to suggest that this error may be due a recent change in
matplotlib
/jupyter
/etc. Maybe the issue was always present, butmatplotlib
only started throwing the error in recent versions?
I was able to reproduce the issue depending on the state of the SCT repo:
- If
matplotlib-inline
is installed in SCT's environment, there is no error. - If
matplotlib-inline
is uninstalled, then the error is thrown:
Traceback (most recent call last):
File "/home/joshua/repos/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_register_multimodal.py", line 34, in <module>
from spinalcordtoolbox.reports import qc2
File "/home/joshua/repos/spinalcordtoolbox/spinalcordtoolbox/reports/qc2.py", line 30, in <module>
import matplotlib
File "/home/joshua/repos/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 1270, in <module>
rcParams['backend'] = os.environ.get('MPLBACKEND')
File "/home/joshua/repos/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/__init__.py", line 738, in __setitem__
raise ValueError(f"Key {key}: {ve}") from None
ValueError: Key backend: 'module://matplotlib_inline.backend_inline' is not a valid value for backend; supported values are ['gtk3agg', 'gtk3cairo', 'gtk4agg', 'gtk4cairo', 'macosx', 'nbagg', 'notebook', 'qtagg', 'qtcairo', 'qt5agg', 'qt5cairo', 'tkagg', 'tkcairo', 'webagg', 'wx', 'wxagg', 'wxcairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
I'm not 100% sure why you only encountered this error sporadically. Perhaps the "sporadic" part was due to the LazyLoading? But, nonetheless, we should be able to fix this by adding matplotlib-inline
to SCT's requirements.txt
.
from spinalcordtoolbox.
Related Issues (20)
- For `sct_analyze_lesion -f`, the atlas ROI spreadsheet columns are unsorted (e.g. 17, 21, 07, 11, etc.)
- model c2c3_disc_models/t2_model.yml does not exist HOT 3
- CI is failing with `pytest`-related import errors during the collection stage HOT 1
- `sct_register_multimodal` is changing the data type when using nearest neighbours interpolation HOT 1
- `sct_analyze_lesion`: add tutorial
- FMRI moco argparse help description refers to non-existent `-p` (should be `-param` instead) HOT 1
- Output ANTs syntax in moco for easier debugging HOT 2
- Suspicious application of a mask in moco HOT 5
- Verbose CLI arg (`sct_apply_transfo -v`) is not passed to the subprocess call to `antsApplyTransforms` HOT 1
- Update SCIseg model to the latest version
- Improve performance of `sct_analyze_lesion -f` by avoiding redundant calls to `np.where` HOT 1
- `matplotlib==3.9.1` no longer installs wheels, instead tries to build on Windows (but fails in CI) HOT 2
- `sct_analyze_lesion` - pandas warnings are mixing with the function output HOT 3
- `sct_analyze_lesion` - sagittal slices are alwayes reported in RPI HOT 1
- Clarify steps for installing SCT onto ComputeCanada Graham (`requirements.txt` conflicts) HOT 10
- `sct_analyze_lesion` crashes if there is no lesion on the midsagittal slice
- `DEPRECATION: Legacy editable install` during `pip install -e .` step of `install_sct` HOT 2
- `sct_analyze_lesion` - add support for spinal levels HOT 1
- `sct_analyze_lesion` - output lesion length and width for the midsagittal slice HOT 1
- `sct_analyze_lesion` - tissue bridges QC - possible improvements HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spinalcordtoolbox.