Skip to content

from matplotlib import animation UnicodeDecodeError #14902

Closed

Description

@tomdean1939

Bug report

Bug summary

In interactive python3 'from matplotlib import animation' causes an error.
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 87: ordinal not in range(128)

Code for reproduction

from matplotlib import animation

Actual outcome


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 737, in <module>
    class ImageMagickWriter(ImageMagickBase, MovieWriter):
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 120, in wrapper
    if writerClass.isAvailable():
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 730, in isAvailable
    return super().isAvailable()
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 427, in isAvailable
    return shutil.which(cls.bin_path()) is not None
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/animation.py", line 724, in bin_path
    binpath = mpl._get_executable_info('magick').executable
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/__init__.py", line 384, in _get_executable_info
    return impl([path, "--version"], r"^Version: ImageMagick (\S*)")
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/__init__.py", line 324, in impl
    args, stderr=subprocess.STDOUT, universal_newlines=True)
  File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.6/subprocess.py", line 425, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "/usr/lib/python3.6/subprocess.py", line 850, in communicate
    stdout = self.stdout.read()
  File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 87: ordinal not in range(128)

Expected outcome
matplotlib.animation would be imported.

I am not sure it ever worked.

Matplotlib version

  • Operating system: Ubuntu 18.04
  • Matplotlib version: 3.1.1
  • Matplotlib backend (print(matplotlib.get_backend())): GTK3Agg
  • Python version: 3.6.8
  • Jupyter version (if applicable):
  • Other libraries:

Python3 came with the distribution and was updated with apt
matplotlib was installed with python3 -m pip install matplotlib. Updated with pip.

Activity

  1. ImportanceOfBeingErnest commented on Jul 27, 2019

    @ImportanceOfBeingErnest
    Member

    Might be related #3837

    Possibly you will get more information with

    import logging
    logging.basicConfig(level=0)
    
  2. jklymak commented on Jul 27, 2019

    @jklymak
    Member

    Not sure this error makes any sense regardless, but do you have imagemagick installed?

  3. tomdean1939 commented on Jul 27, 2019

    @tomdean1939
    Author

    This error stops animation from being import'd.
    And, it is related to imagemagick. Looking at python3.6/encodings/ascii.py, the 'input' that causes the error contains: b'Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114...

    My log does not show imagemagick being installed. Must have either come with the system or some other package required it.
    How does imagemagick get involved?

  4. jklymak commented on Jul 27, 2019

    @jklymak
    Member

    In order to run an animation we call outside packages. You need imagemagick if you use the imagemagick movie writer

    OTOH this error probably shouldn’t happen. Ping @antzer who I think did some work on this recently

  5. ImportanceOfBeingErnest commented on Jul 27, 2019

    @ImportanceOfBeingErnest
    Member

    Here is a pretty similar issue, https://stackoverflow.com/questions/57115893, though with a different error.

    Clearly, the problem is that

    except mpl.ExecutableNotFoundError:

    only checks for some "executable not found", but not for other errors that could happen along the way.

  6. ImportanceOfBeingErnest commented on Jul 27, 2019

    @ImportanceOfBeingErnest
    Member

    Probably #13303 is now causing this to come up. Ping @anntzer (the one with double-N ;-))

  7. tomdean1939 commented on Jul 27, 2019

    @tomdean1939
    Author
  8. ImportanceOfBeingErnest commented on Jul 27, 2019

    @ImportanceOfBeingErnest
    Member

    This makes this issue two-fold:

    1. Even if trying to run the executable were to return total non-sense, the respective writer should just not be registered instead of erroring out. More logging would also help here.
    2. Apparently some versions of imagemagick report different strings back. Of course this should not hinder the use of imagemagick (or in fact any other external tool matplotlib may want to use).
  9. tomdean1939 commented on Jul 27, 2019

    @tomdean1939
    Author
  10. anntzer commented on Jul 27, 2019

    @anntzer
    Contributor

    I guess something like

    diff --git i/lib/matplotlib/__init__.py w/lib/matplotlib/__init__.py
    index 8103bc3d6..99b24483e 100644
    --- i/lib/matplotlib/__init__.py
    +++ w/lib/matplotlib/__init__.py
    @@ -330,7 +330,8 @@ def _get_executable_info(name):
             # at least min_ver (if set); else, raise ExecutableNotFoundError.
             try:
                 output = subprocess.check_output(
    -                args, stderr=subprocess.STDOUT, universal_newlines=True)
    +                args, stderr=subprocess.STDOUT,
    +                universal_newlines=True, errors="replace")
             except subprocess.CalledProcessError as _cpe:
                 if ignore_exit_code:
                     output = _cpe.output

    would work?

  11. tomdean1939 commented on Jul 27, 2019

    @tomdean1939
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions