nvbn / thefuck

Magnificent app which corrects your previous console command.
MIT License
85.65k stars 3.43k forks source link

ModuleNotFoundError: No module named 'distutils' related to #1434 #1444

Open D4llo opened 7 months ago

D4llo commented 7 months ago

The issue may be related to #1434

Opening a terminal throws:

Traceback (most recent call last):
  File "/usr/bin/thefuck", line 5, in <module>
    from thefuck.entrypoints.main import main
  File "/usr/lib/python3.12/site-packages/thefuck/entrypoints/main.py", line 2, in <module>
    from ..system import init_output
  File "/usr/lib/python3.12/site-packages/thefuck/system/__init__.py", line 7, in <module>
    from .unix import *  # noqa: F401,F403
    ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/thefuck/system/unix.py", line 6, in <module>
    from distutils.spawn import find_executable
ModuleNotFoundError: No module named 'distutils'

The output of thefuck --version (something like The Fuck 3.1 using Python 3.5.0 and Bash 4.4.12(1)-release):

The Fuck 3.32-8 using Python 3.12.3 and Bash 5.2.26(1)-release (note that thefuck --version throws:

Traceback (most recent call last):
  File "/usr/bin/thefuck", line 5, in <module>
    from thefuck.entrypoints.main import main
  File "/usr/lib/python3.12/site-packages/thefuck/entrypoints/main.py", line 2, in <module>
    from ..system import init_output
  File "/usr/lib/python3.12/site-packages/thefuck/system/__init__.py", line 7, in <module>
    from .unix import *  # noqa: F401,F403
    ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/thefuck/system/unix.py", line 6, in <module>
    from distutils.spawn import find_executable
ModuleNotFoundError: No module named 'distutils'

Your system (Debian 7, ArchLinux, Windows, etc.):

EndeavourOS 6.8.7-arch1-2

How to reproduce the bug:

open an terminal and thats all

The output of The Fuck with THEFUCK_DEBUG=true exported (typically execute export THEFUCK_DEBUG=true in your shell before The Fuck):

Still failed

Cheers,

Sir-Caljerque commented 7 months ago

yooo, same shit happens to me

specarino commented 7 months ago

According to PEP 632, distutils has been removed from Python 3.12.

A band-aid fix for us users for now would be to follow the above report and just install the python-setuptools package.

Edit: #1404 and/or #1247 appears to fix this, but they are still open PRs

pynmash commented 7 months ago

I did a little research before coming here and discovered the same fix. It's been a while since the last commit. Hope the project isn't abandoned

MaddyGuthridge commented 6 months ago

I installed with pipx, and found that I still ended up with an error even after running pipx inject thefuck distutils.

Traceback (most recent call last):
  File "/home/migue/.local/bin/thefuck", line 5, in <module>
    from thefuck.entrypoints.main import main
  File "/home/migue/.local/pipx/venvs/thefuck/lib64/python3.12/site-packages/thefuck/entrypoints/main.py", line 8, in <module>
    from .. import logs  # noqa: E402
    ^^^^^^^^^^^^^^^^^^^
  File "/home/migue/.local/pipx/venvs/thefuck/lib64/python3.12/site-packages/thefuck/logs.py", line 8, in <module>
    from .conf import settings
  File "/home/migue/.local/pipx/venvs/thefuck/lib64/python3.12/site-packages/thefuck/conf.py", line 1, in <module>
    from imp import load_source
ModuleNotFoundError: No module named 'imp'

Looks like getting thefuck to work nicely with Python 3.12 may be a little more painful than just adding a missing dependency, since I can't find any drop-in replacement for imp (which has been deprecated since Python 3.4, and got removed in Python 3.12, source).

The easiest solution for pipx users is to stick to Python 3.11. For me, this was as simple as

$ sudo dnf install python3.11  # changes depending on your distro
$ pipx reinstall --python python3.11 thefuck
tyush commented 6 months ago

Same issue with me. If you use pipx but don't want to downgrade your system Python version (dangerous if tools from your distro rely on system Python), the following command installs thefuck into a venv with Python 3.11 while keeping the system Python untouched.

$ pipx install --fetch-missing-python --python "3.11" thefuck
$ thefuck --help
usage: thefuck [-v] [-a [ALIAS]] [-l SHELL_LOGGER]
...
$ python --version
Python 3.12.3
virtualritz commented 3 months ago

I have the same issue since I upgraded my Ubuntu from 23.10 to 24.04 today.

McPringle commented 3 weeks ago

Some here on a fresh install of Linux Mint on my new notebook. :-/

KaKi87 commented 1 week ago

Same issue with me. If you use pipx but don't want to downgrade your system Python version (dangerous if tools from your distro rely on system Python), the following command installs thefuck into a venv with Python 3.11 while keeping the system Python untouched.

$ pipx install --fetch-missing-python --python "3.11" thefuck
$ thefuck --help
usage: thefuck [-v] [-a [ALIAS]] [-l SHELL_LOGGER]
...
$ python --version
Python 3.12.3

Thank you !

I also had to uninstall pipx from APT (sudo apt remove pipx) and reinstall it with brew instead (brew install pipx) because Debian & Ubuntu repositories are too outdated for --fetch-missing-python & --python parameters to be available.

Packages previously installed with pipx didn't have to be reinstalled after the switch. I thought so because pipx list still listed the previously installed packages, but they don't actually work, so they have to be reinstalled with pipx install <package> --force.

NiziL commented 4 days ago

Same here, rolling back on python3.11 did the trick for me. For uv users : uv tool install --python 3.11 thefuck

KaKi87 commented 4 days ago

Thank you for making me discover uv !