我正在运行 Python 3.6 版本,操作系统为 Windows 10。我想要展示一个简单的 matplotlib 图表,就像这样:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)
很抱歉,我遇到了错误:
ModuleNotFoundError: No module named 'tkinter'
我尝试通过终端安装tkinter:
> pip install tkinter
Collecting tkinter
Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter
我也尝试了pip install python3-tk
,但是没有成功。我在StackOverflow上找到了几篇文章,介绍了如何正确安装tkinter,但它们都是关于Python 2和/或Linux系统的。我找不到一篇特别针对Windows 10上Python 3.6的文章。
import tkinter
能工作吗?如果能工作,说明 tkinter 已安装。据我所知,Tkinter 在所有 Windows 机器上默认安装,因此似乎是 mathplotlib 的问题。 - Xantium3.6.1
。我将重新安装Python到最新版本,并让您知道发生了什么 :-) - K.Mulier