我从 Jupyter 导出了一个文件为 .py 格式。代码在 Jupyter 上运行良好,但当我尝试直接从命令行运行它时,出现以下错误
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 36, in <module>
import _tkinter
ImportError: No module named '_tkinter'
在处理上述异常的过程中,又发生了另一个异常:
Traceback (most recent call last):
File "analysis.py", line 30, in <module>
import matplotlib.pyplot as plt # NOTE: This was tested with matplotlib v. 2.1.0
File "/usr/local/lib/python3.5/dist-packages/matplotlib/pyplot.py", line 2374, in <module>
switch_backend(rcParams["backend"])
File "/usr/local/lib/python3.5/dist-packages/matplotlib/pyplot.py", line 207, in switch_backend
backend_mod = importlib.import_module(backend_name)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_tkagg.py", line 1, in <module>
from . import _backend_tk
File "/usr/local/lib/python3.5/dist-packages/matplotlib/backends/_backend_tk.py", line 5, in <module>
import tkinter as Tk
File "/usr/lib/python3.5/tkinter/__init__.py", line 38, in <module>
raise ImportError(str(msg) + ', please install the python3-tk package')
两个都python-tk和python3-tk已安装。我在 Jupyter 代码中使用 Python 3.5.2。我见过这种情况线以及许多其他人关于这个问题的文章,但我仍然无法弄清楚。最让我困惑的是,代码确实可以在 Jupyter 上运行,但我导出时无法在终端上运行它。
有人能告诉我如何解决这个问题吗?提前谢谢您。