系统相关
首页 > 系统相关> > Installing matplotlib into Ubuntu 18.04

Installing matplotlib into Ubuntu 18.04

作者:互联网

  File "/home/lee/share/py_lab/matplotlib_animation/src/test001.py", line 2, in <module>
    from matplotlib import animation,pyplot
  File "/home/lee/share/py_lab/env001_matplot_animate/lib/python3.8/site-packages/matplotlib/pyplot.py", line 36, in <module>
    import matplotlib.colorbar
  File "/home/lee/share/py_lab/env001_matplot_animate/lib/python3.8/site-packages/matplotlib/colorbar.py", line 44, in <module>
    import matplotlib.contour as contour
  File "/home/lee/share/py_lab/env001_matplot_animate/lib/python3.8/site-packages/matplotlib/contour.py", line 17, in <module>
    import matplotlib.text as text
  File "/home/lee/share/py_lab/env001_matplot_animate/lib/python3.8/site-packages/matplotlib/text.py", line 16, in <module>
    from .textpath import TextPath  # Unused, but imported by others.
  File "/home/lee/share/py_lab/env001_matplot_animate/lib/python3.8/site-packages/matplotlib/textpath.py", line 11, in <module>
    from matplotlib.mathtext import MathTextParser
  File "/home/lee/share/py_lab/env001_matplot_animate/lib/python3.8/site-packages/matplotlib/mathtext.py", line 27, in <module>
    from PIL import Image
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 68, in <module>
    from PIL import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)

python imports matplotlib from virtual env

PIL from system python path

which leads to version conflict

 

run sudo pip uninstall pillow in system shell

then pip install pillow in virtual env

helloword
/home/lee/share/py_lab/matplotlib_animation/src/test001.py:19: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  pyplot.show()

It means we need a new GUI backend

 

import matplotlib.rcsetup as rcsetup
print(rcsetup.all_backends)
['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']

try:

matplotlib.use('QT5Agg')

then:

File "/home/lee/share/py_lab/env002_matplot_animate/lib/python3.8/site-packages/matplotlib/pyplot.py", line 277, in backend_mod
    locals().update(vars(importlib.import_module(backend_name)))
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/lee/share/py_lab/env002_matplot_animate/lib/python3.8/site-packages/matplotlib/backends/backend_qt5agg.py", line 11, in <module>
    from .backend_qt5 import (
  File "/home/lee/share/py_lab/env002_matplot_animate/lib/python3.8/site-packages/matplotlib/backends/backend_qt5.py", line 16, in <module>
    import matplotlib.backends.qt_editor.figureoptions as figureoptions
  File "/home/lee/share/py_lab/env002_matplot_animate/lib/python3.8/site-packages/matplotlib/backends/qt_editor/figureoptions.py", line 11, in <module>
    from matplotlib.backends.qt_compat import QtGui
  File "/home/lee/share/py_lab/env002_matplot_animate/lib/python3.8/site-packages/matplotlib/backends/qt_compat.py", line 177, in <module>
    raise ImportError("Failed to import any qt binding")
ImportError: Failed to import any qt binding

try:

pip3 install pyqt5

then: 

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

Aborted (core dumped)

 

try:

sudo apt-get install libxcb-xinerama0

then:

 

 

 

 

 

 

 

  

标签:lib,18.04,into,py,Installing,matplotlib,File,import,line
来源: https://blog.csdn.net/qq_39597358/article/details/114187374