英文:
How can I fix importlib on python3.10 so that it can call entry_points() properly?
问题
I am using Python 3.10 on Ubuntu 22.04 working on a project that uses Farama Foundation's gymnasium library. When gymnasium is imported, it uses importlib to get entry points, but when I ran import gymnasium
into IDLE I got the following error:
Traceback (most recent call last):
File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode
exec(code, self.locals)
File "<pyshell#2>", line 1, in <module>
File "/usr/local/lib/python3.10/dist-packages/gymnasium/__init__.py", line 12, in <module>
from gymnasium.envs.registration import (
File "/usr/local/lib/python3.10/dist-packages/gymnasium/envs/__init__.py", line 382, in <module>
load_plugin_envs()
File "/usr/local/lib/python3.10/dist-packages/gymnasium/envs/registration.py", line 565, in load_plugin_envs
for plugin in metadata.entry_points(group=entry_point):
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 1009, in entry_points
return SelectableGroups.load(eps).select(**params)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 459, in load
ordered = sorted(eps, key=by_group)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 1006, in <genexpr>
eps = itertools.chain.from_iterable(
File "/usr/lib/python3.10/importlib/metadata/_itertools.py", line 16, in unique_everseen
k = key(element)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 941, in _normalized_name
return self._name_from_stem(stem) or super()._normalized_name
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 622, in _normalized_name
return Prepared.normalize(self.name)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 871, in normalize
return re.sub(r"[-_.]+", "-", name).lower(). replace('-', '_')
File "/usr/lib/python3.10/re.py", line 209, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
I asked one of the creators of gymnasium about this issue on GitHub, and they asked me to print out a list of entry points, so I ran the following:
from importlib.metadata import *
eps = entry_points()
and got the following error:
Traceback (most recent call last):
File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode
exec(code, self.locals)
File "<pyshell#1>", line 1, in <module>
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 1009, in entry_points
return SelectableGroups.load(eps).select(**params)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 459, in load
ordered = sorted(eps, key=by_group)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 1006, in <genexpr>
eps = itertools.chain.from_iterable(
File "/usr/lib/python3.10/importlib/metadata/_itertools.py", line 16, in unique_everseen
k = key(element)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 941, in _normalized_name
return self._name_from_stem(stem) or super()._normalized_name
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 622, in _normalized_name
return Prepared.normalize(self.name)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 871, in normalize
return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
File "/usr/lib/python3.10/re.py", line 209, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
What this seems to suggest is that one of the names that entry_points()
is searching for is not in the correct format. I am unsure of how to fix this. I am willing to uninstall Python 3.10 completely and reinstall it and all additional packages from scratch, but I would prefer an approach that is less aggressive.
英文:
I am using Python 3.10 on Ubuntu 22.04 working on a project that uses Farama Foundation's gymnasium library. When gymnasium is imported, it uses importlib to get entry points, but when I ran import gymnasium
into IDLE I got the following error:
Traceback (most recent call last):
File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode
exec(code, self.locals)
File "<pyshell#2>", line 1, in <module>
File "/usr/local/lib/python3.10/dist-packages/gymnasium/__init__.py", line 12, in <module>
from gymnasium.envs.registration import (
File "/usr/local/lib/python3.10/dist-packages/gymnasium/envs/__init__.py", line 382, in <module>
load_plugin_envs()
File "/usr/local/lib/python3.10/dist-packages/gymnasium/envs/registration.py", line 565, in load_plugin_envs
for plugin in metadata.entry_points(group=entry_point):
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 1009, in entry_points
return SelectableGroups.load(eps).select(**params)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 459, in load
ordered = sorted(eps, key=by_group)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 1006, in <genexpr>
eps = itertools.chain.from_iterable(
File "/usr/lib/python3.10/importlib/metadata/_itertools.py", line 16, in unique_everseen
k = key(element)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 941, in _normalized_name
return self._name_from_stem(stem) or super()._normalized_name
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 622, in _normalized_name
return Prepared.normalize(self.name)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 871, in normalize
return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
File "/usr/lib/python3.10/re.py", line 209, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
I asked one of the creators of gymnasium about this issue on GitHub, and they asked me to print out a list of entry points, so I ran the following:
from importlib.metadata import *
eps = entry_points()
and got the following error:
Traceback (most recent call last):
File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode
exec(code, self.locals)
File "<pyshell#1>", line 1, in <module>
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 1009, in entry_points
return SelectableGroups.load(eps).select(**params)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 459, in load
ordered = sorted(eps, key=by_group)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 1006, in <genexpr>
eps = itertools.chain.from_iterable(
File "/usr/lib/python3.10/importlib/metadata/_itertools.py", line 16, in unique_everseen
k = key(element)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 941, in _normalized_name
return self._name_from_stem(stem) or super()._normalized_name
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 622, in _normalized_name
return Prepared.normalize(self.name)
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 871, in normalize
return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
File "/usr/lib/python3.10/re.py", line 209, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
What this seems to suggest is that one of the names that entry_points()
is searching for is not in the correct format. I am unsure of how to fix this. I am willing to uninstall Python 3.10 completely and reinstall it and all additional packages from scratch, but I would prefer an approach that is less aggressive.
答案1
得分: 1
尝试这个:
>>> import importlib_metadata as md
>>> dists = md.distributions()
>>> broken = [dist for dist in dists if dist.name is None]
>>> for dist in broken:
... print(dist._path)
它将列出出现问题的分发路径。重新安装或删除它们将停止错误。
[这个人遇到了相同的问题](https://github.com/pypa/twine/issues/774#issuecomment-886657451)
英文:
Try this:
>>> import importlib_metadata as md
>>> dists = md.distributions()
>>> broken = [dist for dist in dists if dist.name is None]
>>> for dist in broken:
... print(dist._path)
It will list the paths of distributions that are the problem. Reinstalling or deleting them will stop the error.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论