matplotlib 不会将图形保存为 raspberrypi 上的文件

matplotlib doesn't save graph as file on raspberrypi

我对 raspberry pi 上的 matplotlib 有疑问 我有以下代码:

import matplotlib.pyplot as plt

data = [100, 200, 500, 700, 300, 200, 500]
x =[1, 2, 3, 4, 5, 6, 7]

plt.plot(x, data, color='w')
plt.xlabel('x axis')
plt.ylabel('y axis')
plt.savefig("test.png")

该代码在我的计算机上运行良好,但在 raspberry pi 上出现以下错误:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/numpy/core/__init__.py", line 22, in <module>
    from . import multiarray
  File "/home/pi/.local/lib/python3.7/site-packages/numpy/core/multiarray.py", line 12, in <module>
    from . import overrides
  File "/home/pi/.local/lib/python3.7/site-packages/numpy/core/overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: /lib/arm-linux-gnueabihf/libm.so.6: version `GLIBC_2.27' not found (required by /home/pi/.local/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-arm-linux-gnueabihf.so)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import matplotlib.pyplot as plt
  File "/home/pi/.local/lib/python3.7/site-packages/matplotlib/__init__.py", line 107, in <module>
    from . import cbook, rcsetup
  File "/home/pi/.local/lib/python3.7/site-packages/matplotlib/cbook/__init__.py", line 28, in <module>
    import numpy as np
  File "/home/pi/.local/lib/python3.7/site-packages/numpy/__init__.py", line 140, in <module>
    from . import core
  File "/home/pi/.local/lib/python3.7/site-packages/numpy/core/__init__.py", line 48, in <module>
    raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.7 from "/usr/local/bin/python3"
  * The NumPy version is: "1.19.4"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: /lib/arm-linux-gnueabihf/libm.so.6: version `GLIBC_2.27' not found (required by /home/pi/.local/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-arm-linux-gnueabihf.so)

pip3 freeze 说我的numpy版本是1.19.4

python3 --version 说我的 python 版本是 3.7.0

我该如何解决这个问题?

这帮我修好了 要解决 linux 上的问题,您需要安装以下软件包: sudo apt-get install libatlas-base-dev

https://github.com/Pex2892/PETAL/issues/2