Closed
Description
Bug summary
Version 3.7 broke using relative paths in plt.style.use()
raising a TypeError
. It was working fine in 3.6. Prepending with a ./
as suggested in the error message did not help.
Code for reproduction
import matplotlib.pyplot as plt
plt.sylte.use("../mystyle.style")
Actual outcome
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[11], line 1
----> 1 plt.style.use("../mystyle.style")
File ~/envs/py39/lib/python3.9/site-packages/matplotlib/style/core.py:153, in use(style)
151 pkg, _, name = style.rpartition(".")
152 try:
--> 153 path = (importlib_resources.files(pkg)
154 / f"{name}.{STYLE_EXTENSION}")
155 style = _rc_params_in_file(path)
156 except (ModuleNotFoundError, IOError) as exc:
157 # There is an ambiguity whether a dotted name refers to a
158 # package.style_name or to a dotted file path. Currently,
(...)
161 # either use Path objects or be prepended with "./" and use
162 # the slash as marker for file paths.
File ~/envs/py39/lib/python3.9/site-packages/importlib_resources/_common.py:46, in package_to_anchor.<locals>.wrapper(anchor, package)
44 elif anchor is undefined:
45 return func()
---> 46 return func(anchor)
File ~/envs/py39/lib/python3.9/site-packages/importlib_resources/_common.py:56, in files(anchor)
51 @package_to_anchor
52 def files(anchor: Optional[Anchor] = None) -> Traversable:
53 """
54 Get a Traversable resource for an anchor.
55 """
---> 56 return from_package(resolve(anchor))
File ~/envs/py39/lib/python3.9/functools.py:888, in singledispatch.<locals>.wrapper(*args, **kw)
884 if not args:
885 raise TypeError(f'{funcname} requires at least '
886 '1 positional argument')
--> 888 return dispatch(args[0].__class__)(*args, **kw)
File ~/envs/py39/lib/python3.9/site-packages/importlib_resources/_common.py:82, in _(cand)
80 @resolve.register
81 def _(cand: str) -> types.ModuleType:
---> 82 return importlib.import_module(cand)
File ~/envs/py39/lib/python3.9/importlib/__init__.py:122, in import_module(name, package)
119 if not package:
120 msg = ("the 'package' argument is required to perform a relative "
121 "import for {!r}")
--> 122 raise TypeError(msg.format(name))
123 for character in name:
124 if character != '.':
TypeError: the 'package' argument is required to perform a relative import for '../mystyle'
Expected outcome
Style is loaded.
Additional information
No response
Operating system
No response
Matplotlib Version
3.7.0
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
3.9.16
Jupyter version
6.5.2
Installation
conda
fjosw
Metadata
Metadata
Assignees
Labels
No labels