我正在尝试将tkinter与matplotlib一起使用。
当我尝试这样做时,我收到以下错误。我已经阅读了每一个信号线程和我可以找到的文章,这些都已经说到了pip uninstall然后pip重新安装matplotlib,我做了很多次没有快乐。
这是我的结局
> 14, in <module>
> line for line in traceback.format_stack()
> matplotlib.use("TkAgg")
matplotlib.use("TkAgg")
<
以下是我要导入的内容
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
我真的很感激任何关于此的建议。
完整错误消息在
下面 n [1]: runfile('C:/Users/carl-/Desktop/Programing/Projects/Kitties
Mastermind/SandBox.py',
wdir='C:/Users/carl-/Desktop/Programing/Projects/Kitties Mastermind')
C:/Users/carl-/Desktop/Programing/Projects/Kitties
Mastermind/SandBox.py:2: UserWarning:
This call to matplotlib.use() has no effect because the backend has
already
been chosen; matplotlib.use() must be called *before* pylab,
matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
The backend was *originally* set to
'module://ipykernel.pylab.backend_inline' by the following code:
File "C:\Users\carl-\Anaconda3\lib\site-
packages\spyder\utils\ipython\start_kernel.py", line 245, in <module>
main()
File "C:\Users\carl-\Anaconda3\lib\site-
packages\spyder\utils\ipython\start_kernel.py", line 229, in main
kernel.initialize()
File "<decorator-gen-124>", line 2, in initialize
File "C:\Users\carl-\Anaconda3\lib\site-
packages\traitlets\config\application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "C:\Users\carl-\Anaconda3\lib\site-
packages\ipykernel\kernelapp.py", line 464, in initialize
self.init_code()
File "C:\Users\carl-\Anaconda3\lib\site-
packages\IPython\core\shellapp.py", line 260, in init_code
self._run_exec_lines()
File "C:\Users\carl-\Anaconda3\lib\site-
packages\IPython\core\shellapp.py", line 286, in _run_exec_lines
self.shell.run_cell(line, store_history=False)
File "C:\Users\carl-\Anaconda3\lib\site-
packages\ipykernel\zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "C:\Users\carl-\Anaconda3\lib\site-
packages\IPython\core\interactiveshell.py", line 2698, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "C:\Users\carl-\Anaconda3\lib\site-
packages\IPython\core\interactiveshell.py", line 2808, in run_ast_nodes
if self.run_code(code, result):
File "C:\Users\carl-\Anaconda3\lib\site-
packages\IPython\core\interactiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-e27d371d6baa>", line 1, in <module>
get_ipython().magic('matplotlib inline')
File "C:\Users\carl-\Anaconda3\lib\site-
packages\IPython\core\interactiveshell.py", line 2146, in magic
return self.run_line_magic(magic_name, magic_arg_s)
File "C:\Users\carl-\Anaconda3\lib\site-
packages\IPython\core\interactiveshell.py", line 2067, in
run_line_magic
result = fn(*args,**kwargs)
File "<decorator-gen-108>", line 2, in matplotlib
File "C:\Users\carl-\Anaconda3\lib\site-
packages\IPython\core\magic.py", line 187, in <lambda>
call = lambda f, *a, **k: f(*a, **k)
File "C:\Users\carl-\Anaconda3\lib\site-
packages\IPython\core\magics\pylab.py", line 99, in matplotlib
gui, backend = self.shell.enable_matplotlib(args.gui)
File "C:\Users\carl-\Anaconda3\lib\site-
packages\IPython\core\interactiveshell.py", line 2930, in
enable_matplotlib
pt.activate_matplotlib(backend)
File "C:\Users\carl-\Anaconda3\lib\site-
packages\IPython\core\pylabtools.py", line 307, in activate_matplotlib
matplotlib.pyplot.switch_backend(backend)
File "C:\Users\carl-\Anaconda3\lib\site-packages\matplotlib\pyplot.py",
line 232, in switch_backend
matplotlib.use(newbackend, warn=False, force=True)
File "C:\Users\carl-\Anaconda3\lib\site-
packages\matplotlib\__init__.py", line 1305, in use
reload(sys.modules['matplotlib.backends'])
File "C:\Users\carl-\Anaconda3\lib\importlib\__init__.py", line 166, in
reload
_bootstrap._exec(spec, module)
File "C:\Users\carl-\Anaconda3\lib\site-
packages\matplotlib\backends\__init__.py", line 14, in <module>
line for line in traceback.format_stack()
matplotlib.use("TkAgg")