AttributeError: module 'importlib' has no attribute 'abc'. Did you mean: '_abc'?
hornekyle opened this issue · comments
After installing pycg using pip, I get the following traceback when trying to run on a sample code.
Traceback (most recent call last):
File "/home/kyle/.local/bin/pycg", line 8, in <module>
sys.exit(main())
File "/home/kyle/.local/lib/python3.10/site-packages/pycg/__main__.py", line 79, in main
cg.analyze()
File "/home/kyle/.local/lib/python3.10/site-packages/pycg/pycg.py", line 155, in analyze
self.do_pass(PreProcessor, True,
File "/home/kyle/.local/lib/python3.10/site-packages/pycg/pycg.py", line 144, in do_pass
self.import_manager.install_hooks()
File "/home/kyle/.local/lib/python3.10/site-packages/pycg/machinery/imports.py", line 203, in install_hooks
loader = get_custom_loader(self)
File "/home/kyle/.local/lib/python3.10/site-packages/pycg/machinery/imports.py", line 34, in get_custom_loader
class CustomLoader(importlib.abc.SourceLoader):
AttributeError: module 'importlib' has no attribute 'abc'. Did you mean: '_abc'?
It seems like the the use of importlib.abs.SourceLoader does not work since the subpackage importlib.abc is not imported directly.
For my installation I have temporally fixed the problem by including the following import:
import importlib.abs as iabs
I then adjusted the class definition as follows:
class CustomLoader(iabc.SourceLoader):
I think there is a better way to do this, but I thought you should at least know of the error. I'm running Python 3.10.x on Arch Linux.
Hey @hornekyle, thanks for the report. Yep, this seems to be an issue with an update to Python 3.10 (I've only tested up to 3.9). I think the best solution would be to change the import to
from importlib import abc
...
class CustomLoader(abc.SourceLoader):