Windows 10, anaconda/CPU env, using the latest clone.
I'm currently getting ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'wx' is currently running when trying to label frames.
I have tried to recreate the environment but it doesnt seem to help. Have already tried on two windows PC but the problem seems to occur at the same point.
This is the entire code that appeared when I typed deeplabcut.label_frames(config_path).
In [5]: deeplabcut.label_frames(config_path)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-0fc28e79d144> in <module>()
----> 1 deeplabcut.label_frames(config_path)
c:\users\shaun\anaconda3\envs\dlc-windowscpu\lib\site-packages\deeplabcut\generate_training_dataset\trainingsetmanipulation.py in label_frames(config)
212
213 # labeling_toolbox.show(config,Screens,scale_w,scale_h, winHack, img_scale)
--> 214 labeling_toolbox.show(config)
215 os.chdir(startpath)
216
c:\users\shaun\anaconda3\envs\dlc-windowscpu\lib\site-packages\deeplabcut\generate_training_dataset\labeling_toolbox.py in show(config)
648 def show(config):
649 app = wx.App()
--> 650 frame = MainFrame(None,config).Show()
651 app.MainLoop()
652
c:\users\shaun\anaconda3\envs\dlc-windowscpu\lib\site-packages\deeplabcut\generate_training_dataset\labeling_toolbox.py in __init__(self, parent, config)
148 vSplitter = wx.SplitterWindow(topSplitter)
149
--> 150 self.image_panel = ImagePanel(vSplitter, config,self.gui_size)
151 self.choice_panel = ScrollPanel(vSplitter)
152 vSplitter.SplitVertically(self.image_panel,self.choice_panel, sashPosition=self.gui_size[0]*0.8)
c:\users\shaun\anaconda3\envs\dlc-windowscpu\lib\site-packages\deeplabcut\generate_training_dataset\labeling_toolbox.py in __init__(self, parent, config, gui_size, **kwargs)
40 self.figure = matplotlib.figure.Figure()
41 self.axes = self.figure.add_subplot(1, 1, 1)
---> 42 self.canvas = FigureCanvas(self, -1, self.figure)
43 self.orig_xlim = None
44 self.orig_ylim = None
c:\users\shaun\anaconda3\envs\dlc-windowscpu\lib\site-packages\matplotlib\backends\backend_wx.py in __init__(self, parent, id, figure)
589 """
590
--> 591 FigureCanvasBase.__init__(self, figure)
592 # Set preferred window size hint - helps the sizer (if one is
593 # connected)
c:\users\shaun\anaconda3\envs\dlc-windowscpu\lib\site-packages\matplotlib\backend_bases.py in __init__(self, figure)
1580
1581 def __init__(self, figure):
-> 1582 self._fix_ipython_backend2gui()
1583 self._is_idle_drawing = True
1584 self._is_saving = False
c:\users\shaun\anaconda3\envs\dlc-windowscpu\lib\site-packages\matplotlib\backend_bases.py in _fix_ipython_backend2gui(cls)
1627 try:
1628 mpl.rcParamsOrig["backend"] = mpl.rcParams["backend"]
-> 1629 ip.enable_matplotlib()
1630 finally:
1631 mpl.rcParamsOrig["backend"] = orig_origbackend
c:\users\shaun\anaconda3\envs\dlc-windowscpu\lib\site-packages\IPython\core\interactiveshell.py in enable_matplotlib(self, gui)
2913 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
2914
-> 2915 pt.activate_matplotlib(backend)
2916 pt.configure_inline_support(self, backend)
2917
c:\users\shaun\anaconda3\envs\dlc-windowscpu\lib\site-packages\IPython\core\pylabtools.py in activate_matplotlib(backend)
307
308 import matplotlib.pyplot
--> 309 matplotlib.pyplot.switch_backend(backend)
310
311 # This must be imported last in the matplotlib series, after
c:\users\shaun\anaconda3\envs\dlc-windowscpu\lib\site-packages\matplotlib\pyplot.py in switch_backend(newbackend)
228 "Cannot load backend {!r} which requires the {!r} interactive "
229 "framework, as {!r} is currently running".format(
--> 230 newbackend, required_framework, current_framework))
231
232 rcParams['backend'] = rcParamsDefault['backend'] = newbackend
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'wx' is currently running
Is there any solution to this problem? Thanks.
Same error here
Attaching more log files to help.
Although the error becomes visible on Jupyter when you try to label the data, the terminal outputs an error when importing deeplabcut.
Older installations did not have this problem and still do not have this problem, but when trying to install on new PCs, this problem occurs.
When importing deeplabcut following message is shown on the terminal:
ERROR:tornado.application:Exception in callback functools.partial(<function wrap.<locals>.null_wrapper at 0x000001B167F06620>)
Traceback (most recent call last):
File "C:\Users\vsharma98\AppData\Local\Continuum\anaconda3\envs\jinujinu\lib\site-packages\tornado\ioloop.py", line 758, in _run_callback
ret = callback()
File "C:\Users\vsharma98\AppData\Local\Continuum\anaconda3\envs\jinujinu\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "C:\Users\vsharma98\AppData\Local\Continuum\anaconda3\envs\jinujinu\lib\site-packages\ipykernel\kernelbase.py", line 306, in advance_eventloop
eventloop(self)
File "C:\Users\vsharma98\AppData\Local\Continuum\anaconda3\envs\jinujinu\lib\site-packages\ipykernel\eventloops.py", line 238, in loop_tk
app.tk.createfilehandler(stream.getsockopt(zmq.FD), READABLE, notifier)
AttributeError: '_tkinter.tkapp' object has no attribute 'createfilehandler'
Even when explicitly exporting the environment from a different working Anaconda environment, once
pip install deeplabcut is run, it seems to overwrite a lot of the libraries to it's most recent versions, and hence coming back to the same error.
[EDIT] Attached environments from working past installations.
workingEnv-explicit.txt
workingEnv-list.txt
I managed to make it work by importing matplotlib and forcing it to use another backend instead of tkagg.
Here’s what I keyed in:
import matplotlib
matplotlib.use(‘Agg’)
This was done just before proceeding with the deeplabcut.label_frames function.
Can you be more specific on the version? This is the dev 2.0.6.3 git cloned, or the 2.0.6.2 via pip install?
Also, that Anaconda behavior is sadly correct; they are not true env like Docker, as they share backend code...
I am using the dev 2.0.6.3 git cloned.
We tested both Windows and Ubuntu and do not get this behavior. Is there a possibility you resent the backend somewhere in your code prior to running this step?
And, can you tell me which version of matplotlib you are using?
import matplotlib
matplotlib.__version__
Hi there,
Sorry to re-up a closed issue. I'm using DeepLabCut to run inference on a remote machine, i.e. a cluster with no GUI. I'm using deeplabcut 2.07.1. Matplotlib version was 3.0.3. I'm only using one function, analyze_videos. To get my code to run, I had to simply comment out the mpl.use('TkAgg') command in the following places:
Given that I'm not using any visualization functions (due to pure inference), none of these referenced functions were necessary for my use.
Here's a traceback if you're interested:
Traceback (most recent call last):
File "myfile.py", line 15, in <module>
from deeplabcut import analyze_videos
File "/home/jpb35/anaconda3/envs/tf/lib/python3.6/site-packages/deeplabcut/__init__.py", line 29, in <module>
from deeplabcut import generate_training_dataset
File "/home/jpb35/anaconda3/envs/tf/lib/python3.6/site-packages/deeplabcut/generate_training_dataset/__init__.py", line 23, in <module>
from deeplabcut.generate_training_dataset.trainingsetmanipulation import *
File "/home/jpb35/anaconda3/envs/tf/lib/python3.6/site-packages/deeplabcut/generate_training_dataset/trainingsetmanipulation.py", line 24, in <module>
mpl.use('TkAgg')
File "/home/jpb35/anaconda3/envs/tf/lib/python3.6/site-packages/matplotlib/__init__.py", line 1391, in use
switch_backend(name)
File "/home/jpb35/anaconda3/envs/tf/lib/python3.6/site-packages/matplotlib/pyplot.py", line 222, in switch_backend
newbackend, required_framework, current_framework))
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
@jbohnslav do you set DLClight=True?
I am also getting this error, but I get it when I:
import deeplabcut
Traceback (most recent call last):
File "
File "/home/knight/cmerrick/.conda/envs/ecog/lib/python3.6/site-packages/deeplabcut/__init__.py", line 29, in
from deeplabcut import generate_training_dataset
File "/home/knight/cmerrick/.conda/envs/ecog/lib/python3.6/site-packages/deeplabcut/generate_training_dataset/__init__.py", line 19, in
from deeplabcut.generate_training_dataset.labeling_toolbox import *
File "/home/knight/cmerrick/.conda/envs/ecog/lib/python3.6/site-packages/deeplabcut/generate_training_dataset/labeling_toolbox.py", line 27, in
from deeplabcut.utils import auxiliaryfunctions
File "/home/knight/cmerrick/.conda/envs/ecog/lib/python3.6/site-packages/deeplabcut/utils/__init__.py", line 1, in
from deeplabcut.utils.make_labeled_video import *
File "/home/knight/cmerrick/.conda/envs/ecog/lib/python3.6/site-packages/deeplabcut/utils/make_labeled_video.py", line 34, in
mpl.use('TkAgg')
File "/home/knight/cmerrick/.conda/envs/ecog/lib/python3.6/site-packages/matplotlib/__init__.py", line 1391, in use
switch_backend(name)
File "/home/knight/cmerrick/.conda/envs/ecog/lib/python3.6/site-packages/matplotlib/pyplot.py", line 222, in switch_backend
newbackend, required_framework, current_framework))
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
Hi There the same error for me when I try to import deeplabcut 2.0.9.
With ubuntu 18.04, python 3.7.4 and Matplotlib 3.0.3.
Any recommendations?
Many Thanks D
import deeplabcut
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dimitris/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/deeplabcut/__init__.py", line 29, in <module>
from deeplabcut import generate_training_dataset
File "/home/dimitris/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/deeplabcut/generate_training_dataset/__init__.py", line 19, in <module>
from deeplabcut.generate_training_dataset.labeling_toolbox import *
File "/home/dimitris/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/deeplabcut/generate_training_dataset/labeling_toolbox.py", line 27, in <module>
from deeplabcut.utils import auxiliaryfunctions
File "/home/dimitris/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/deeplabcut/utils/__init__.py", line 1, in <module>
from deeplabcut.utils.make_labeled_video import *
File "/home/dimitris/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/deeplabcut/utils/make_labeled_video.py", line 34, in <module>
mpl.use('TkAgg')
File "/home/dimitris/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/matplotlib/__init__.py", line 1391, in use
switch_backend(name)
File "/home/dimitris/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/matplotlib/pyplot.py", line 222, in switch_backend
newbackend, required_framework, current_framework))
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
@dtsaop what version of matplotlib are you using?
@MMathisLab I am using Matplotlib 3.0.3.
Thanks for the prompt reply.
python 3.7.4 might be an issue; as far as I know, DLC is only supported in python 3.6.X - can you make a new environment using this and test: http://www.mousemotorlab.org/s/dlc-ubuntu-GPU.yaml
@MMathisLab I have another issue also when I am trying to set the environment with $ conda env create -f dlc-ubuntu-GPU.yaml. I am getting the following error
Collecting package metadata (repodata.json): done
Solving environment: failed
ResolvePackageNotFound:
openblas==0.3.5=h9ac9557_1001
So I am using the following suggested method:
conda create -n DLC2 python=3.6
then:
source activate DLC2
then run:
pip install deeplabcut
wxPython for 18.04:
either: pip install wxpython==4.0.3 or:
pip install https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04/wxPython-4.0.3-cp36-cp36m-linux_x86_64.whl
TF:
pip install tensorflow-gpu==1.14
I will try with python 3.6 and I will let you know.
@MMathisLab
The same error with python 3.6.9
import deeplabcut
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dimitris/anaconda3/envs/DLC2/lib/python3.6/site-packages/deeplabcut/__init__.py", line 29, in <module>
from deeplabcut import generate_training_dataset
File "/home/dimitris/anaconda3/envs/DLC2/lib/python3.6/site-packages/deeplabcut/generate_training_dataset/__init__.py", line 19, in <module>
from deeplabcut.generate_training_dataset.labeling_toolbox import *
File "/home/dimitris/anaconda3/envs/DLC2/lib/python3.6/site-packages/deeplabcut/generate_training_dataset/labeling_toolbox.py", line 27, in <module>
from deeplabcut.utils import auxiliaryfunctions
File "/home/dimitris/anaconda3/envs/DLC2/lib/python3.6/site-packages/deeplabcut/utils/__init__.py", line 1, in <module>
from deeplabcut.utils.make_labeled_video import *
File "/home/dimitris/anaconda3/envs/DLC2/lib/python3.6/site-packages/deeplabcut/utils/make_labeled_video.py", line 34, in <module>
mpl.use('TkAgg')
File "/home/dimitris/anaconda3/envs/DLC2/lib/python3.6/site-packages/matplotlib/__init__.py", line 1391, in use
switch_backend(name)
File "/home/dimitris/anaconda3/envs/DLC2/lib/python3.6/site-packages/matplotlib/pyplot.py", line 222, in switch_backend
newbackend, required_framework, current_framework))
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
hmm... I made a better yaml, here: http://www.mousemotorlab.org/s/dlc-ubuntu-GPU.yaml
but, not clear why you're getting this error; can you
import matplotlib
matplotlib.use(‘Agg’)
then import dlc?
@MMathisLab the new yaml file works fine. Thanks
The same error when importing dlc after
import matplotlib
matplotlib.use(‘Agg’)
I'm at bit at a loss as I could never reproduce this error on my systems; perhaps try some other variants of matplotlib, as that package is the source of this issue... https://stackoverflow.com/questions/55811545/importerror-cannot-load-backend-tkagg-which-requires-the-tk-interactive-fra
@MMathisLab I reinstall everything and now I am getting the following error
ImportError: OpenCV loader: missing configuration file: ['config-3.6.py', 'config-3.py']. Check OpenCV installation.
I am completely lost now!! :)
I have also been struggling with the error:
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'wx' is currently running
resulting from the command
import deeplabcut
and just wanted to share the solution I found. As mentioned above, importing matplotlib 3.0.3, and then using matplotlib.use('Agg') is the solution, but these two steps have to be done before importing deeplabcut. So, the steps to follow in this order are:
Restart the kernel
1) restart kernel
import matplotlib
matplotlib.use('Agg')
import deeplabcut
Most helpful comment
I managed to make it work by importing matplotlib and forcing it to use another backend instead of tkagg.
Here’s what I keyed in:
This was done just before proceeding with the
deeplabcut.label_framesfunction.