Help us understand the problem. What is going on with this article?

AWS EC2インスタンス上でmatplotloibでimport Error

More than 1 year has passed since last update.

エラー

    import matplotlib.pyplot as plt
  File "/home/ec2-user/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/home/ec2-user/anaconda3/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/home/ec2-user/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py", line 15, in <module>
    from .backend_qt5 import (
  File "/home/ec2-user/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py", line 19, in <module>
    import matplotlib.backends.qt_editor.figureoptions as figureoptions
  File "/home/ec2-user/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py", line 20, in <module>
    import matplotlib.backends.qt_editor.formlayout as formlayout
  File "/home/ec2-user/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/formlayout.py", line 54, in <module>
    from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
  File "/home/ec2-user/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_compat.py", line 140, in <module>
    from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

解決策

matplotlib.pyplotインポート前に以下を宣言

import matplotlib
matplotlib.use("tkagg")
import matplotlib.pyplot as plt
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away