简体   繁体   English

无法将 Matplotlib 与 Raspberry PI4 一起使用

[英]Unable to use Matplotlib with Raspberry PI4

I am trying to use Python on my PI4.我正在尝试在我的 PI4 上使用 Python。 I have a very simple program:我有一个非常简单的程序:

import numpy as np
import matplotlib.pyplot as plt
x = np.array([1, 3, 4, 6])
y = np.array([2, 3, 5, 1])
plt.plot(x,y)
plt.show()

I have install matplotlib with:我已经安装了 matplotlib :

sudo apt install python3-matplotlib

I use IDLE shell 3.9.2 and I have the following error:我使用 IDLE shell 3.9.2 并且出现以下错误:

RuntimeError: module compiled against API version 0xf but this version of numpy is 0xd
Traceback (most recent call last):
  File "/home/pi/Python/Test01.py", line 2, in <module>
    import matplotlib.pyplot as plt
  File "/usr/local/lib/python3.9/dist-packages/matplotlib/__init__.py", line 109, in <module>
    from . import _api, _version, cbook, docstring, rcsetup
  File "/usr/local/lib/python3.9/dist-packages/matplotlib/rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "/usr/local/lib/python3.9/dist-packages/matplotlib/colors.py", line 56, in <module>
    from matplotlib import _api, cbook, scale
  File "/usr/local/lib/python3.9/dist-packages/matplotlib/scale.py", line 23, in <module>
    from matplotlib.ticker import (
  File "/usr/local/lib/python3.9/dist-packages/matplotlib/ticker.py", line 136, in <module>
    from matplotlib import transforms as mtransforms
  File "/usr/local/lib/python3.9/dist-packages/matplotlib/transforms.py", line 46, in <module>
    from matplotlib._path import (
ImportError: numpy.core.multiarray failed to import

I can't solve that!!我解决不了!!

I had this exact same issue but finally figured out a solution: Here's what I did:我遇到了完全相同的问题,但最终找到了解决方案:这就是我所做的:

  1. Type the following in the terminal:在终端中键入以下内容:

     sudo apt update sudo apt remove python3-numpy sudo apt install libatlas3-base

    In removing numpy, other files and directories will also be removed, including matplotlib.在删除 numpy 时,其他文件和目录也将被删除,包括 matplotlib。

  2. If using Thonny IDE, select 'Tools' -> 'Manage packages...'如果使用 Thonny IDE、select '工具' -> '管理包...'

  3. In the search bar of the new window, type numpy , then click 'Search on PyPI'在新的 window 的搜索栏中,输入numpy ,然后单击“在 PyPI 上搜索”

  4. Click on the first search result to install!点击第一个搜索结果安装!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM