You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ImportError: cannot import name 'MetadataPathFinder' from 'importlib.metadata' #82523
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/importlib/metadata/__init__.py", line 365, in versionreturn distribution(package).version
File "/usr/local/lib/python3.8/importlib/metadata/__init__.py", line 338, in distributionreturn Distribution.from_name(package)
File "/usr/local/lib/python3.8/importlib/metadata/__init__.py", line 159, in from_name
dists = resolver(name)
File "<frozen importlib._bootstrap_external>", line 1381, in find_distributionsImportError: cannot import name 'MetadataPathFinder' from 'importlib.metadata' (/usr/local/lib/python3.8/importlib/metadata/__init__.py)
3.8.0b4 (tags/v3.8.0b4:d93605d, Aug 29 2019, 23:21:28) [MSC v.1916 64 bit (AMD64)]
2.22.0
FlorimondManca commented on Oct 2, 2019
FlorimondMancamannequin
Mannequin
More actions
Can confirm this on 3.8.0rc1+ / macOS Mojave:
$ python -c "import importlib.metadata; print(list(importlib.metadata.distributions()))"Traceback (most recent call last): File "<string>", line 1, in <module> File "/Users/florimond/.pyenv/versions/3.8-dev/lib/python3.8/importlib/metadata/__init__.py", line 175, in <genexpr> resolver() File "<frozen importlib._bootstrap_external>", line 1381, in find_distributionsImportError: cannot import name 'MetadataPathFinder' from 'importlib.metadata' (/Users/florimond/.pyenv/versions/3.8-dev/lib/python3.8/importlib/metadata/__init__.py)
I discovered this pytest started failing on 3.8-dev because it uses importlib.metadata.distributions() internally.
3.8.0b4+ used to be fine I believe. I'd assume this is a rather critical bug?
I believe importlib/metadata/init was moved to importlib.metadata. I’ll inspect the repo for correctness, but there may be another issue with the old files lingering.
I installed b4 clean. I also installed 3.8.0rc1 over 3.8.0b4 and everything is fine.
It's possible that installing 3.8.0b4 over 3.8.0b3 would leave the old package lingering. Can you confirm that's how 3.8.0rc1 was installed?
I've crafted this command which should correct the situation in such an environment::
python -c "import importlib.metadata, shutil, pathlib; file = pathlib.Path(importlib.metadata.__file__); str(file).endswith('__init__.py') and shutil.rmtree(file.parent) and print('removed', file.parent)"
Please give that a try and see if it corrects the condition.
atuining commented on Oct 2, 2019
atuiningmannequin
MannequinAuthor
More actions
Yes. I had tried b3 earlier, installed b4 over b3 and then rc1 over b4. Removing the cruft using the command you specified caused the problem to go away.
Closing as not a bug as this seems to be an issue from installing over a b3 or earlier build where the importlib/metadata/ directory gets left behind and thus take priority in import over importlib/metadata.py.
python -c "import importlib.metadata, shutil, pathlib; file = pathlib.Path(importlib.metadata.__file__); str(file).endswith('__init__.py') and shutil.rmtree(file.parent) and print('removed', file.parent)"
I wonder if the fix (e.g. running the script above) should be more visible, perhaps in some documentation somewhere, instead of having to dig this up from the bugtracker.
Is it possible for the Python installer itself to execute that script?
Given that this issue only affects those who upgraded from beta versions, I'm inclined to say it shouldn't be part of the installer, and that the long tail of users affected probably can track it down here.
I don't feel strongly about it though.
Zheaoli commented on Feb 21, 2020
Zheaolimannequin
Mannequin
More actions
Hello Mariatta
I have tested the code below on 3.8.1 what's installed by pyenv on my Mac
Activity
atuining commentedon Oct 1, 2019
Running the suggested code found at https://docs.python.org/3.8/whatsnew/3.8.html regarding the new importlib.metadata module
yields the error
Savier commentedon Oct 2, 2019
on windows
FlorimondManca commentedon Oct 2, 2019
Can confirm this on 3.8.0rc1+ / macOS Mojave:
I discovered this pytest started failing on 3.8-dev because it uses
importlib.metadata.distributions()internally.3.8.0b4+ used to be fine I believe. I'd assume this is a rather critical bug?
tirkarthi commentedon Oct 2, 2019
The library was synced with https://bugs.python.org/issue38121 which seems to be related to this.
jaraco commentedon Oct 2, 2019
I believe importlib/metadata/init was moved to importlib.metadata. I’ll inspect the repo for correctness, but there may be another issue with the old files lingering.
jaraco commentedon Oct 2, 2019
I've confirmed that the
metadatadirectory doesn't exist in the repo. It also doesn't appear on my Python 3.8.0b4 installation on macOS:I installed b4 clean. I also installed 3.8.0rc1 over 3.8.0b4 and everything is fine.
It's possible that installing 3.8.0b4 over 3.8.0b3 would leave the old package lingering. Can you confirm that's how 3.8.0rc1 was installed?
I've crafted this command which should correct the situation in such an environment::
python -c "import importlib.metadata, shutil, pathlib; file = pathlib.Path(importlib.metadata.__file__); str(file).endswith('__init__.py') and shutil.rmtree(file.parent) and print('removed', file.parent)"
Please give that a try and see if it corrects the condition.
atuining commentedon Oct 2, 2019
Yes. I had tried b3 earlier, installed b4 over b3 and then rc1 over b4. Removing the cruft using the command you specified caused the problem to go away.
isidentical commentedon Oct 2, 2019
https://gitlab.com/python-devs/importlib_metadata/issues/92
brettcannon commentedon Oct 2, 2019
Closing as not a bug as this seems to be an issue from installing over a b3 or earlier build where the importlib/metadata/ directory gets left behind and thus take priority in import over importlib/metadata.py.
Mariatta commentedon Jan 16, 2020
Just wanted to add that I got the same error in Python 3.8.1.
I ran the script that @jaraco wrote above:
python -c "import importlib.metadata, shutil, pathlib; file = pathlib.Path(importlib.metadata.__file__); str(file).endswith('__init__.py') and shutil.rmtree(file.parent) and print('removed', file.parent)"
I wonder if the fix (e.g. running the script above) should be more visible, perhaps in some documentation somewhere, instead of having to dig this up from the bugtracker.
Is it possible for the Python installer itself to execute that script?
Thanks.
jaraco commentedon Jan 16, 2020
Given that this issue only affects those who upgraded from beta versions, I'm inclined to say it shouldn't be part of the installer, and that the long tail of users affected probably can track it down here.
I don't feel strongly about it though.
Zheaoli commentedon Feb 21, 2020
Hello Mariatta
I have tested the code below on 3.8.1 what's installed by pyenv on my Mac
it works correctly.
I think it depends on the tool what's used to install python