desc
desc copied to clipboard
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
Hello
I have been trying to reproduce this. However, I keep getting an error with TkAgg.
This is the block that is giving me an error (with a few modifications, but the original gives me the same message)
import os
os.environ['PYTHONHASHSEED'] = '0'
import matplotlib
matplotlib.use('TKAgg', force = True)
import matplotlib.pyplot as plt
import desc
import pandas as pd
import numpy as np
import scanpy.api as sc
from time import time
import sys
import matplotlib.pyplot as plt
%matplotlib inline
sc.settings.set_figure_params(dpi=300)
The output is:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-9cdf2f4155a6> in <module>
4 import matplotlib
5 matplotlib.use('TKAgg', force = True)
----> 6 import matplotlib.pyplot as plt
7
8 import desc
/data04/projects04/MarianaBoroni/lbbc_members/lib/conda_envs/diogoamb/lib/python3.9/site-packages/matplotlib/pyplot.py in <module>
2228 dict.__setitem__(rcParams, "backend", rcsetup._auto_backend_sentinel)
2229 # Set up the backend.
-> 2230 switch_backend(rcParams["backend"])
2231
2232 # Just to be safe. Interactive mode can be turned on without
/data04/projects04/MarianaBoroni/lbbc_members/lib/conda_envs/diogoamb/lib/python3.9/site-packages/matplotlib/pyplot.py in switch_backend(newbackend)
273 if (current_framework and required_framework
274 and current_framework != required_framework):
--> 275 raise ImportError(
276 "Cannot load backend {!r} which requires the {!r} interactive "
277 "framework, as {!r} is currently running".format(
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
It seemed to be a problem with TkAgg, (hence why I modified the first few lines). But when I run
print("Using:", matplotlib.get_backend())
It seems the backend TkAgg can be used fine:
Using: TkAgg
Here is the output when I run exactly what is in the ttutorial
import os
os.environ['PYTHONHASHSEED'] = '0'
import desc
import pandas as pd
import numpy as np
import scanpy.api as sc
from time import time
import sys
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
sc.settings.set_figure_params(dpi=300)
`---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-792688ab25c3> in <module>
1 import os
2 os.environ['PYTHONHASHSEED'] = '0'
----> 3 import desc
4 import pandas as pd
5 import numpy as np
/data04/projects04/MarianaBoroni/lbbc_members/lib/conda_envs/diogoamb/lib/python3.9/site-packages/desc/__init__.py in <module>
1 #from . import original as og
----> 2 from . import tools
3 from . import models
4 from . import datasets
5
/data04/projects04/MarianaBoroni/lbbc_members/lib/conda_envs/diogoamb/lib/python3.9/site-packages/desc/tools/__init__.py in <module>
2 from scanpy.preprocessing import normalize_per_cell, highly_variable_genes, log1p, scale
3
----> 4 from .test import run_desc_test
5 from .read import read_10X
6 from .write import write_desc_result
/data04/projects04/MarianaBoroni/lbbc_members/lib/conda_envs/diogoamb/lib/python3.9/site-packages/desc/tools/test.py in <module>
1
2 from ..datasets import pbmc_processed
----> 3 from ..models.desc import train
4
5
/data04/projects04/MarianaBoroni/lbbc_members/lib/conda_envs/diogoamb/lib/python3.9/site-packages/desc/models/__init__.py in <module>
----> 1 from .desc import train
2
/data04/projects04/MarianaBoroni/lbbc_members/lib/conda_envs/diogoamb/lib/python3.9/site-packages/desc/models/desc.py in <module>
22 #if we have a display use a plotting backend
23 if havedisplay:
---> 24 matplotlib.use('TkAgg')
25 else:
26 matplotlib.use('Agg')
/data04/projects04/MarianaBoroni/lbbc_members/lib/conda_envs/diogoamb/lib/python3.9/site-packages/matplotlib/__init__.py in use(backend, force)
1142 # user does not have the libraries to support their
1143 # chosen backend installed.
-> 1144 plt.switch_backend(name)
1145 except ImportError:
1146 if force:
/data04/projects04/MarianaBoroni/lbbc_members/lib/conda_envs/diogoamb/lib/python3.9/site-packages/matplotlib/pyplot.py in switch_backend(newbackend)
273 if (current_framework and required_framework
274 and current_framework != required_framework):
--> 275 raise ImportError(
276 "Cannot load backend {!r} which requires the {!r} interactive "
277 "framework, as {!r} is currently running".format(
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running`
Any ideas?