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

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

Open
D4llo opened this issue Apr 29, 2024 · 10 comments
Open

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

D4llo opened this issue Apr 29, 2024 · 10 comments

Comments

@D4llo
Copy link

D4llo commented Apr 29, 2024

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
Copy link

yooo, same shit happens to me

@specarino
Copy link

specarino commented May 1, 2024

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
Copy link

pynmash commented May 2, 2024

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
Copy link
Contributor

MaddyGuthridge commented May 13, 2024

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
Copy link

tyush commented May 24, 2024

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
Copy link

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

@McPringle
Copy link

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

@KaKi87
Copy link

KaKi87 commented Nov 22, 2024

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
Copy link

NiziL commented Nov 27, 2024

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

@KaKi87
Copy link

KaKi87 commented Nov 27, 2024

Thank you for making me discover uv !

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

10 participants