Tag Archives: Matplotlib

Solve the problem of attributeerror: module ‘Matplotlib’ has no attribute ‘verb

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

Recently, when using Matplotlib in the process of using pychar in Linux, we can’t draw a picture, and always prompt an error

/usr/bin/python3.5 /home/leo/PycharmProjects/untitled1/Euler.py
Traceback (most recent call last):
  File "/home/leo/PycharmProjects/untitled1/Euler.py", line 5, in <module>
    import matplotlib.pyplot as plt
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/home/leo/pycharm-2017.3.4/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 17, in <module>
    verbose = matplotlib.verbose
AttributeError: module 'matplotlib' has no attribute 'verbose'

According to the file prompted with error, enter the file prompted in the last line and enter the file

from matplotlib.backend_bases import FigureManagerBase, ShowBase
from matplotlib.backends.backend_agg import FigureCanvasAgg
from matplotlib.figure import Figure

HOST = 'localhost'
PORT = os.getenv("PYCHARM_MATPLOTLIB_PORT")
PORT = int(PORT) if PORT is not None else None
PORT = PORT if PORT != -1 else None
index = int(os.getenv("PYCHARM_MATPLOTLIB_INDEX", 0))

rcParams = matplotlib.rcParams
verbose = matplotlib.verbose

The error is in verb = Matplotlib. Verb

Because in Python 3, it’s verb in Matplotlib

!!!!!!!!!! Note: capital V

Change it over and run it. The problem is solved perfectly

ModuleNotFoundError: No module named ‘PyQt4’ [Spyder Import matplotlib Error]

I just learned Matplotlib recently, and I want to play in Anaconda’s Spyder

The code is as follows (in fact, it’s not important, mainly because matplotlib.pyplot is imported and an error is reported)

# -*- coding: utf-8 -*-
"""
Created on Thu Jul 12 21:36:51 2018

@author: asus
"""
print("b")

import matplotlib.pyplot as plt
print("a")

a= [1,2,3]
b= [1,2,3]

plt.plot(a,b)
plt.show()

error message:

File "C:\Users\asus\Anaconda3\lib\site-packages\matplotlib\backends\qt_compat.py", line 157, in <module>
    from PyQt4 import QtCore, QtGui

ModuleNotFoundError: No module named 'PyQt4'

The problem is QT_ Compat.py file

The error indicates that PyQt4 can’t be found. The direct solution is to install PyQt4 package. However, after several times (taking two or three days) of various data searching and various attempts, all failed

The basic contradiction is that pyqt5 is configured by default in Anaconda environment, while PyQt4 is called by default in Matplotlib, which is a version problem

Finally, back to QT_ Compat.py file

if rcParams['backend'] == 'Qt5Agg':
    QT_RC_MAJOR_VERSION = 5
elif rcParams['backend'] == 'Qt4Agg':
    QT_RC_MAJOR_VERSION = 4

Notice the above code, try changing the default version


solutions

In QT_ Add code to compat.py file:

rcParams['backend']='Qt5Agg'

Namely:

""" A Qt API selector that can be used to switch between PyQt and PySide.
"""

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import six

import os
import logging
import sys
from matplotlib import rcParams

#rcParams['backend']='PyQt5'    # added by chen to adapt the matplotlib
rcParams['backend']='Qt5Agg'    # added by chen to adapt the matplotlib
#print("----------------"+rcParams['backend'])

_log = logging.getLogger(__name__)

(ignore comment line)

Save, run the original file, success

Error in installing SciPy and Matplotlib

This article gives you a comprehensive understanding of Java object serialization and deserialization>>>

My computer is Windows 7 64 bit. Error in installing SciPy:

>python setup.py install

Note: if you need reliable uninstall behavior, then install
with pip instead of using `setup.py install`:

  - `pip install .`       (from a git repo or downloaded source
                           release)
  - `pip install scipy`   (last SciPy release on PyPI)


lapack_opt_info:
lapack_mkl_info:
  libraries mkl_rt not found in ['D:\\app\\Python27\\lib', 'C:\\', 'D:\\app\\Python27\\libs']
  NOT AVAILABLE

...

    config = setup_module.configuration(*args)
  File "scipy\linalg\setup.py", line 20, in configuration
    raise NotFoundError('no lapack/blas resources found')
numpy.distutils.system_info.NotFoundError: no lapack/blas resources found

Error in installing Matplotlib:

>python setup.py build
============================================================================
Edit setup.cfg to change the build options

BUILDING MATPLOTLIB
            matplotlib: yes [2.0.0]
                python: yes [2.7.8 (default, Jun 30 2014, 16:08:48) [MSC
                        v.1500 64 bit (AMD64)]]
              platform: yes [win32]

REQUIRED DEPENDENCIES AND EXTENSIONS
                 numpy: yes [version 1.12.0]
                   six: yes [using six version 1.10.0]
              dateutil: yes [using dateutil version 2.5.3]
           functools32: yes [functools32 was not found. It is required
                        forPython versions prior to 3.2]
          subprocess32: yes [subprocess32 was not found. It used  for Python
                        versions prior to 3.2 to improves functionality on
                        Linux and OSX]
                  pytz: yes [using pytz version 2016.6.1]
                cycler: yes [cycler was not found. pip will attempt to
                        install it after matplotlib.]
               tornado: yes [using tornado version 4.3]
             pyparsing: yes [pyparsing was not found. It is required for
                        mathtext support. pip/easy_install may attempt to
                        install it after matplotlib.]
                libagg: yes [pkg-config information for 'libagg' could not
                        be found. Using local copy.]
              freetype: no  [The C/C++ header for freetype (ft2build.h)
                        could not be found.  You may need to install the
                        development package.]
                   png: no  [The C/C++ header for png (png.h) could not be
                        found.  You may need to install the development
                        package.]
                 qhull: yes [pkg-config information for 'qhull' could not be
                        found. Using local copy.]

OPTIONAL SUBPACKAGES
           sample_data: yes [installing]
              toolkits: yes [installing]
                 tests: no  [skipping due to configuration]
        toolkits_tests: no  [skipping due to configuration]

OPTIONAL BACKEND EXTENSIONS
                macosx: no  [Mac OS-X only]
                qt5agg: no  [PyQt5 not found]
                qt4agg: yes [installing, Qt: 4.8.6, PyQt: 4.8.6; PySide not
                        found]
               gtk3agg: no  [Requires pygobject to be installed.]
             gtk3cairo: no  [Requires cairocffi or pycairo to be installed.]
                gtkagg: no  [Requires pygtk]
                 tkagg: yes [installing; run-time loading from Python Tcl /
                        Tk]
                 wxagg: no  [requires wxPython]
                   gtk: no  [Requires pygtk]
                   agg: yes [installing]
                 cairo: no  [cairocffi or pycairo not found]
             windowing: yes [installing]

OPTIONAL LATEX DEPENDENCIES
                dvipng: no
           ghostscript: no
                 latex: no
               pdftops: no

OPTIONAL PACKAGE DATA
                  dlls: no  [skipping due to configuration]

============================================================================
                        * The following required packages can not be built:
                        * freetype, png

Current solution: install unofficial numpy, SciPy and Matplotlib

Address: http://www.lfd.uci.edu/~gohlke/pythonlibs/

Download numpy-1.12.0 + mkl-cp27-cp27m-win_ amd64.whl ,scipy-0.18.1-cp27-cp27m-win_ Amd64.whl and matplotlib-2.0.0-cp27-cp27m-win_ amd64.whl。 Then enter the directory where the file is located and use pip to install it

pip install numpy-1.12.0+mkl-cp27-cp27m-win_amd64.whl

pip install scipy-0.18.1-cp27-cp27m-win_amd64.whl

pip install matplotlib-2.0.0-cp27-cp27m-win_amd64.whl