【问题标题】:import matplotlib.pyplot as plt, ImportError: libGL.so.1: cannot open shared object file: No such file or directoryimport matplotlib.pyplot as plt, ImportError: libGL.so.1: cannot open shared object file: No such file or directory
【发布时间】:2018-05-22 10:38:40
【问题描述】:

import matplotlib.pyplot as plt 在 python2.7、anaconda3 上出错。

错误是ImportError: libGL.so.1: cannot open shared object file: No such file or directory

错误报告

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/serving/anaconda3/envs/python27/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/serving/anaconda3/envs/python27/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/serving/anaconda3/envs/python27/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.py", line 16, in <module>
    from .backend_qt5 import QtCore
  File "/serving/anaconda3/envs/python27/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 26, in <module>
    import matplotlib.backends.qt_editor.figureoptions as figureoptions
  File "/serving/anaconda3/envs/python27/lib/python2.7/site-packages/matplotlib/backends/qt_editor/figureoptions.py", line 20, in <module>
    import matplotlib.backends.qt_editor.formlayout as formlayout
  File "/serving/anaconda3/envs/python27/lib/python2.7/site-packages/matplotlib/backends/qt_editor/formlayout.py", line 56, in <module>
    from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
  File "/serving/anaconda3/envs/python27/lib/python2.7/site-packages/matplotlib/backends/qt_compat.py", line 128, in <module>
    from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

conda 列表是

$conda list
cairo 1.14.8 0 defaults
certifi 2016.2.28 py27_0 defaults
cycler 0.10.0 py27_0 defaults
dbus 1.10.20 0 defaults
expat 2.1.0 0 defaults
fontconfig 2.12.1 3 defaults
freetype 2.5.5 2 defaults
functools32 3.2.3.2 py27_0 defaults
glib 2.50.2 1 defaults
gst-plugins-base 1.8.0 0 defaults
gstreamer 1.8.0 0 defaults
harfbuzz 0.9.39 2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
icu 54.1 0 defaults
jpeg 9b 0 defaults
libffi 3.2.1 1 defaults
libgcc 5.2.0 0 defaults
libgfortran 3.0.0 1 defaults
libiconv 1.14 0 defaults
libpng 1.6.30 1 defaults
libxcb 1.12 1 defaults
libxml2 2.9.4 0 defaults
matplotlib 2.0.2 np113py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
mkl 2017.0.3 0 defaults
numpy 1.13.1 py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
openssl 1.0.2l 0 defaults
pandas 0.20.3 py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
pango 1.40.3 1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
patsy 0.4.1 py27_0 defaults
pcre 8.39 1 defaults
pip 9.0.1 py27_1 defaults
pixman 0.34.0 0 defaults
pycairo 1.10.0 py27_0 defaults
pyparsing 2.2.0 py27_0 defaults
pyqt 5.6.0 py27_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
python 2.7.13 0 defaults
python-dateutil 2.6.1 py27_0 defaults
pytz 2017.2 py27_0 defaults
qt 5.6.2 5 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
qt5 5.3.1 1 dsdale24
readline 6.2 2 defaults
scikit-learn 0.19.0 np113py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
scipy 0.19.1 np113py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
setuptools 36.4.0 py27_1 defaults
sip 4.18 py27_0 defaults
six 1.10.0 py27_0 defaults
sqlite 3.13.0 0 defaults
statsmodels 0.8.0 np113py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
subprocess32 3.2.7 py27_0 defaults
tk 8.5.18 0 defaults
wheel 0.29.0 py27_0 defaults
zlib 1.2.11 0 defaults
(python27)

【问题讨论】:

标签: python matplotlib anaconda


【解决方案1】:

以下命令对我有用:

sudo apt update
sudo apt install libgl1-mesa-glx

【讨论】:

    【解决方案2】:
    import matplotlib 
    matplotlib.use("Agg") 
    import matplotlib.pyplot as plt
    

    这对我有用

    【讨论】:

    【解决方案3】:

    Dhanisha 的回答很好,因为我在上面添加了解释

    删除

    import matplotlib.pyplot as plt
    

    添加

    import matplotlib
    matplotlib.use("Agg")
    import matplotlib.pyplot as plt
    

    这种行为背后的原因是如果您在服务器交换机上运行它,则没有 gui 支持或非交互模式。如果您在 jupyter notebook 上运行相同的代码,它会正常工作。

    查看以下链接

    https://matplotlib.org/faq/howto_faq.html

    https://github.com/matplotlib/matplotlib/issues/9954

    【讨论】:

      猜你喜欢
      • 2020-11-05
      • 2021-02-16
      • 1970-01-01
      • 2020-04-10
      • 1970-01-01
      • 2023-02-25
      • 2020-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多