From 90dfb0b5d557977e9cf65e960bccd975a0376f8a Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Mon, 23 Oct 2023 15:06:58 -0500 Subject: [PATCH 1/3] Try/except import of Axes3D On some installs, the `mpl_toolkits` namespace package gets an old version which uses deprecated (And removed) code from the main library. On such the import of Axes3D will error with an `ImportError`. This prevents users from using any of `matplotlib`, since it is imported unconditionally by default. This just try/excepts the imports (and adjusts the registration code accordingly) to allow users to continue using matplotlib (though not 3D and possibly not other mpl_toolkits) even with older installs occluding the mpl_toolkits. --- lib/matplotlib/projections/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/projections/__init__.py b/lib/matplotlib/projections/__init__.py index 16a5651da1d1..17a5fadd2691 100644 --- a/lib/matplotlib/projections/__init__.py +++ b/lib/matplotlib/projections/__init__.py @@ -55,7 +55,11 @@ from .. import axes, _docstring from .geo import AitoffAxes, HammerAxes, LambertAxes, MollweideAxes from .polar import PolarAxes -from mpl_toolkits.mplot3d import Axes3D + +try: + from mpl_toolkits.mplot3d import Axes3D +except ImportError: + Axes3D = None class ProjectionRegistry: @@ -87,8 +91,12 @@ def get_projection_names(self): HammerAxes, LambertAxes, MollweideAxes, - Axes3D, ) +if Axes3D is not None: + projection_registry.register(Axes3D) +else: + # remove from namespace if not importable + del Axes3D def register_projection(cls): From 865e87c82144b11ce43d06912be196b70b7c6730 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Tue, 24 Oct 2023 00:52:05 -0500 Subject: [PATCH 2/3] Add a warning --- lib/matplotlib/projections/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/matplotlib/projections/__init__.py b/lib/matplotlib/projections/__init__.py index 17a5fadd2691..7941cf7e8e5d 100644 --- a/lib/matplotlib/projections/__init__.py +++ b/lib/matplotlib/projections/__init__.py @@ -59,6 +59,10 @@ try: from mpl_toolkits.mplot3d import Axes3D except ImportError: + import warnings + warnings.warn("Unable to import Axes3D. This may be due to multiple versions of" + "Matplotlib being installed (e.g. as a system package and as a pip" + "package). As a result, the 3D projection is not available.") Axes3D = None From 0b8b37e7deab69923fc85338e3da114b19f28ce3 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Wed, 25 Oct 2023 15:21:51 -0500 Subject: [PATCH 3/3] Fix spacing on line breaks Co-authored-by: Elliott Sales de Andrade --- lib/matplotlib/projections/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/projections/__init__.py b/lib/matplotlib/projections/__init__.py index 7941cf7e8e5d..8ce118986065 100644 --- a/lib/matplotlib/projections/__init__.py +++ b/lib/matplotlib/projections/__init__.py @@ -60,8 +60,8 @@ from mpl_toolkits.mplot3d import Axes3D except ImportError: import warnings - warnings.warn("Unable to import Axes3D. This may be due to multiple versions of" - "Matplotlib being installed (e.g. as a system package and as a pip" + warnings.warn("Unable to import Axes3D. This may be due to multiple versions of " + "Matplotlib being installed (e.g. as a system package and as a pip " "package). As a result, the 3D projection is not available.") Axes3D = None pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy