Up matplotlib の import でのエラー 作成: 2021-04-17
更新: 2021-04-17


    import matplotlib.pyplot にエラーが返される:
      (venv) $ python >>> import matplotlib.pyplot as plt Unable to init server: Could not connect: Connection refused Unable to init server: Could not connect: Connection refused (.:7348): Gdk-CRITICAL **: 16:12:36.744: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed (.:7348): Gdk-CRITICAL **: 16:12:36.750: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed >>>

    matplotlib のチェックを兼ねて,upgrade をコマンドを試す:
      (venv) $ pip install -U matplotlib  ‥‥ Attempting uninstall: matplotlib Found existing installation: matplotlib 3.0.2 Not uninstalling matplotlib at /usr/lib/python3/dist-packages, outside environment /home/pi/venv Can't uninstall 'matplotlib'. No files were found to uninstall. Successfully installed matplotlib-3.4.1 pillow-8.2.0 pyparsing-2.4.7

    改めて,import matplotlib.pyplot をする:
      (venv) $ python >>> import matplotlib.pyplot as plt Matplotlib is building the font cache; this may take a moment. >>>

    "Matplotlib is building the font cache; this may take a moment." のメッセージが現れるのは初回だけで,次回からは無くなる:
      (venv) $ python >>> import matplotlib.pyplot as plt >>>