Skip to content

Ubuntu Installation : ImportError: No module named 'matplotlib.externals' #1906

Closed

Description

@wmbm

I tried to install the latest ObSpy version (first time on this computer) via the description provided for Linux/Ubuntu. I'm on a Ubuntu 16.04 LTS OS and running python3. The installation worked fine but using the read function gives the below error.

Installation instructions followed:
https://github.com/obspy/obspy/wiki/Installation-on-Linux-via-Apt-Repository

I have looked elsewhere and it seems to be an issue between having multiple python versions on my computer. Not sure how to resolve this

from obspy import read
FILE_PATH_ = "/home/example.mseed"
st = read(FILE_PATH_)

gives

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-ba5ca716a935> in <module>()
      2 # https://github.com/obspy/obspy/wiki/Installation-on-Linux-via-Apt-Repository
      3 
----> 4 from obspy import read
      5 FILE_PATH_ = "/home/codepan1/Downloads/Package_1506336094435.mseed"
      6 st = read(FILE_PATH_)

/usr/lib/python3/dist-packages/obspy/__init__.py in <module>()
     46 from obspy.core.trace import Trace  # NOQA
     47 from obspy.core.stream import Stream, read
---> 48 from obspy.core.event import read_events, Catalog
     49 from obspy.core.inventory import read_inventory, Inventory  # NOQA
     50 

/usr/lib/python3/dist-packages/obspy/core/event/__init__.py in <module>()
     27     Comment, CompositeTime, ConfidenceEllipsoid, CreationInfo, DataUsed,
     28     QuantityError, ResourceIdentifier, TimeWindow, WaveformStreamID)
---> 29 from .catalog import Catalog, read_events
     30 from .event import Event, EventDescription
     31 from .magnitude import (

/usr/lib/python3/dist-packages/obspy/core/event/catalog.py in <module>()
     41 from .base import CreationInfo, ResourceIdentifier
     42 
---> 43 from .event import Event
     44 
     45 EVENT_ENTRY_POINTS = ENTRY_POINTS['event']

/usr/lib/python3/dist-packages/obspy/core/event/event.py in <module>()
     24 from obspy.core.event.header import (
     25     EventType, EventTypeCertainty, EventDescriptionType)
---> 26 from obspy.imaging.source import plot_radiation_pattern, _setup_figure_and_axes
     27 
     28 from .base import (_event_type_class_factory,

/usr/lib/python3/dist-packages/obspy/imaging/source.py in <module>()
     19 
     20 import numpy as np
---> 21 from mpl_toolkits.mplot3d import Axes3D  # NOQA
     22 from matplotlib.cm import get_cmap
     23 

/usr/lib/python3/dist-packages/mpl_toolkits/mplot3d/__init__.py in <module>()
      2                         unicode_literals)
      3 
----> 4 from matplotlib.externals import six
      5 
      6 from .axes3d import Axes3D

ImportError: No module named 'matplotlib.externals'

Activity

  1. megies commented on Sep 25, 2017

    @megies
    Member

    Looks like this could be a packaging problem (in any case, not in obspy, but in Debian/Ubuntu's matplotlib).

    Can you try if the following code example works (i doubt it):
    https://matplotlib.org/examples/mplot3d/contour3d_demo3.html

  2. added
    DEBissues related to Debian/Ubuntu packaging / packages
    on Sep 25, 2017
  3. added this to the 1.1.0 milestone on Sep 25, 2017
  4. added
    release blockercritical issues blocking the corresponding future release
    on Sep 25, 2017
  5. megies commented on Sep 25, 2017

    @megies
    Member

    Looks like you're being affected by matplotlib/matplotlib#6556, in any case we need to sort this out for Ubuntu xenial..

  6. wmbm commented on Sep 26, 2017

    @wmbm
    Author

    As expected, the 3dcontour example has the same issue with importing externals. Are there any known fixes for this issue?

  7. megies commented on Sep 26, 2017

    @megies
    Member

    In principle this can only be fixed by an updated package from Ubuntu packaging teams.. but I'm not sure about their policy regarding non-security-related bugfixes.

    What we can probably do is to avoid exposing that import on any obspy import..

    /usr/lib/python3/dist-packages/obspy/imaging/source.py in <module>()
         19 
         20 import numpy as np
    ---> 21 from mpl_toolkits.mplot3d import Axes3D  # NOQA
         22 from matplotlib.cm import get_cmap
         23 
    

    i.e. move that import inside the routines where it's actually used. That won't fix the problem in general, but at least it will then only affect those respective routines..

  8. megies commented on Sep 26, 2017

    @megies
    Member

    As a quick-and-dirty fix, you could modify this file (as root): /usr/lib/python3/dist-packages/obspy/imaging/source.py

    --- a/obspy/imaging/source.py
    +++ b/obspy/imaging/source.py
    @@ -18,7 +18,6 @@ from __future__ import (absolute_import, division, print_function,
     from future.builtins import *  # NOQA @UnusedWildImport
     
     import numpy as np
    -from mpl_toolkits.mplot3d import Axes3D  # NOQA
     from matplotlib.cm import get_cmap
     
     from obspy.core.util import MATPLOTLIB_VERSION
    @@ -42,6 +41,7 @@ def _setup_figure_and_axes(kind, fig=None, subplot_size=4.0):
             :meth:`obspy.core.event.event.Event.plot`, parameter `kind`).
         """
         import matplotlib.pyplot as plt
    +    from mpl_toolkits.mplot3d import Axes3D  # NOQA
         # make 2d layout of kind parameter
         if isinstance(kind[0], (list, tuple)):
             nrows = len(kind)
  9. added a commit that references this issue on Sep 26, 2017
  10. megies commented on Sep 26, 2017

    @megies
    Member
  11. krischer commented on Sep 26, 2017

    @krischer
    Member

    Moving the Axes3D object to the functions that actually require it might be a good idea in any case. It should also reduce initial import times.

  12. tacaswell commented on Sep 26, 2017

    @tacaswell

    This looks more like the OP has crossed installations of different versions (one from sudo pip and one from the package manager). The mpl_toolkit is from the pip installation (and expect the base matplotlib to have the external modules) where as I strongly suspect that debian is de-bundling six and patching out the external module all together.

  13. megies commented on Sep 27, 2017

    @megies
    Member

    one from sudo pip and one from the package manager

    @tacaswell how do you come to that conclusion? To my knowledge, sudo pip would end up under /usr/lib/python../site-packages whereas packaged stuff goes to ../dist-packages/. (I didn't really check in some while, have to admit).

    @wmbm can you comment on this? Did you run commands like sudo pip install ...?

  14. wmbm commented on Sep 27, 2017

    @wmbm
    Author

    The quick and dirty fix recommended by @megies worked.

    I have previously done sudo pip install ... commands, but can't exactly remember in this case.

  15. megies commented on Sep 27, 2017

    @megies
    Member

    I have previously done sudo pip install ... commands

    Messing with manual installations in the Python env handled by the systems' package manager is the highway to the danger zone. And you're bound to end up in non-replicable problems that you're on your own with..

    I'm closing this, until someone else on a clean Ubuntu Xenial can confirm this one.

  16. tacaswell commented on Sep 28, 2017

    @tacaswell

    @megies It was based on the thought that we had changed the imports so the offending file was from the wrong version, however it looks like me missed one. This was fixed in matplotlib/matplotlib#9237

  17. QuLogic commented on Sep 28, 2017

    @QuLogic
    Member

    That PR didn't change mplot3d though; I'm not sure that was ever broken as I've tested ObsPy against 2.0 before. Still not sure what's up here.

  18. megies commented on Sep 29, 2017

    @megies
    Member

    I just tried this in a docker xenial container, and I got no error, so I'd blame it on a broken environment unless somebody can confirm on a clean xenial system Python.

    from mpl_toolkits.mplot3d import Axes3D
    from matplotlib.externals import six
    
  19. added a commit that references this issue on May 8, 2018
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

    DEBissues related to Debian/Ubuntu packaging / packagesexternalIt's not our fault!release blockercritical issues blocking the corresponding future release

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions