Thanks to visit codestin.com
Credit goes to github.com

Skip to content

installing matplotlib changes behavior of importlib #19612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
odoublewen opened this issue Mar 1, 2021 · 1 comment
Closed

installing matplotlib changes behavior of importlib #19612

odoublewen opened this issue Mar 1, 2021 · 1 comment

Comments

@odoublewen
Copy link

odoublewen commented Mar 1, 2021

Bug report

After installing matplotlib, import importlib causes importlib.machinery to be available.

Before installing matplotlib (or after uninstalling it), import importlib.machinery is necessary to access the machinery module.

This may seem benign (after all, I'm not saying matplotlib breaks importlib) but I lost a chunk of time tracing down the source of the inconsistency. I can't see any reason why this package should change importlib's behavior.

Code for reproduction

Expected behavior

$ python -c 'import importlib; print(importlib.machinery)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'importlib' has no attribute 'machinery'

Actual behavior

$ pip install matplotlib
Looking in indexes: https://pypi.org/simple
Collecting matplotlib
  Using cached matplotlib-3.3.4-cp38-cp38-manylinux1_x86_64.whl (11.6 MB)
...
Successfully installed matplotlib-3.3.4

$ python -c 'import importlib; print(importlib.machinery)'
<module 'importlib.machinery' from '/opt/python/Python-3.8.1/Lib/importlib/machinery.py'>

Matplotlib version

  • Operating system: confirmed on linux (ubuntu 14.04, 18.04) and macos 10.15
  • Matplotlib version: 3.3.4
  • Python version: 3.8.6
@QuLogic
Copy link
Member

QuLogic commented Mar 2, 2021

I can reproduce this in a new venv. Looking at sys.modules, a key difference is:

'mpl_toolkits': <module 'mpl_toolkits' (namespace)>,

Presumably, this is a side effect of a namespace package existing. I guess we can call this a bug in importlib, but in either case, there is a thought to remove the namespace package, so closing for #5327.

@QuLogic QuLogic closed this as completed Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants