Skip to content
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

Python 3.13.1: No module named 'imp' #1489

Open
autext opened this issue Jan 3, 2025 · 4 comments
Open

Python 3.13.1: No module named 'imp' #1489

autext opened this issue Jan 3, 2025 · 4 comments

Comments

@autext
Copy link

autext commented Jan 3, 2025

i'm using python 3.13.1, and i have encountered a compatibility issue, i think.
when I run 'thefuck', it reports an error:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\softwares\Python313\Scripts\thefuck.exe\__main__.py", line 4, in <module>
    from thefuck.entrypoints.main import main
  File "D:\softwares\Python313\Lib\site-packages\thefuck\entrypoints\main.py", line 8, in <module>
    from .. import logs  # noqa: E402
    ^^^^^^^^^^^^^^^^^^^
  File "D:\softwares\Python313\Lib\site-packages\thefuck\logs.py", line 8, in <module>
    from .conf import settings
  File "D:\softwares\Python313\Lib\site-packages\thefuck\conf.py", line 1, in <module>
    from imp import load_source
ModuleNotFoundError: No module named 'imp'
@tjtrabue
Copy link

tjtrabue commented Jan 4, 2025

I'm facing the same issue with the same Python version.

@AxterD
Copy link

AxterD commented Jan 8, 2025

Same here, python 3.12.8

@wandleshen
Copy link

Since Python 3.12 has removed the imp module, a possible solution is to either use Python 3.11 or replace the imp module calls with importlib. With this link, the imp.load_source() should be replaced with

import importlib.util
import importlib.machinery

def load_source(modname, filename):
    loader = importlib.machinery.SourceFileLoader(modname, filename)
    spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
    module = importlib.util.module_from_spec(spec)
    # The module is always executed and not cached in sys.modules.
    # Uncomment the following line to cache the module.
    # sys.modules[module.__name__] = module
    loader.exec_module(module)
    return module

@Unknownuserfrommars
Copy link

Since Python 3.12 has removed the imp module, a possible solution is to either use Python 3.11 or replace the imp module calls with importlib. With this link, the imp.load_source() should be replaced with

import importlib.util
import importlib.machinery

def load_source(modname, filename):
    loader = importlib.machinery.SourceFileLoader(modname, filename)
    spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
    module = importlib.util.module_from_spec(spec)
    # The module is always executed and not cached in sys.modules.
    # Uncomment the following line to cache the module.
    # sys.modules[module.__name__] = module
    loader.exec_module(module)
    return module

Thanks a lot @wandleshen surely helps me a lot!

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

5 participants