matplotlib.pyplot 不工作!

Pra*_*hna 0 ipython matplotlib 14.04 anaconda jupyter

我正在使用 Jupyter Notebook,但 matplotlib.pyplot 不起作用。我在 Ubuntu 14.04 中使用 Python 2.7。

错误消息的图像

kar*_*rel 6

您的代码收到以下错误消息:

ImportError: numpy.core.multiarray failed to import
Run Code Online (Sandbox Code Playgroud)

像这样更改你的 Python 代码,然后首先在终端中测试它:

ImportError: numpy.core.multiarray failed to import
Run Code Online (Sandbox Code Playgroud)

如果您还安装了 python-matplotlib,则在当前 Jupyter Notebook 中启用绘图的第一行代码是 %matplotlib inline

您的 Jupyter Notebook 还显示另一条错误消息:

RuntimeError: module compile against API version 0xa but this version of numpy is 0x9
Run Code Online (Sandbox Code Playgroud)

来自 Anaconda 的 numpy 与 ipython 或您安装的其他一些软件包不兼容。如果您从默认 Ubuntu 存储库安装了 python-numpy、ipython 和 python-matplotlib 软件包,则不会发生这种情况。我已经使用命令在 Ubuntu 14.04 中安装了 Jupyter Notebook,sudo apt-get -y install ipython ipython-notebook && pip install --user jupyter并将它与 ipython、python-matplotlib 和 python-numpy 一起使用,也来自默认的 Ubuntu 存储库,没有任何问题。

要在 Ubuntu 18.04-19.10 中安装 jupyter-notebook,请打开终端并输入:

sudo apt install python-all python3-pip python3-notebook jupyter jupyter-core python-ipykernel
Run Code Online (Sandbox Code Playgroud)

要在 Ubuntu 20.04 及更高版本中安装 jupyter-notebook,请打开终端并键入:

sudo apt install python-all python3-pip jupyter-notebook jupyter   
Run Code Online (Sandbox Code Playgroud)