ModuleNotFoundError: No module named 'dnf'

dnf
Traceback (most recent call last):
File “/usr/bin/dnf”, line 61, in
from dnf.cli import main
ModuleNotFoundError: No module named ‘dnf’
/usr/bin/dnf" “I’m getting an error like ‘no such directory exists’ as described above. I’m also encountering errors when I type ‘yum’.”

Have you been playing with the python env or used pip recently?
Post the output for

python
from dnf.cli import main
>>>
$ python
Python 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 14.0.1 20240411 (Red Hat 14.0.1-0)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dnf.cli import main
>>>

We need more information to understand the cause of your problem. When a system can’t find files that are part of the basic install you may have a corrupt filesystem (often occurs rebooting a system after “disk full” or a crash), failing storage media where problems occur on a system that appears to be running normally, or other hardware issues.

In such cases it is best to boot from known good media such as the Fedora Workstation Live Installer. You can use this to copy important data to another drive, check the “health” of the system drive using Gnome Disks, and make sure the problem drive has adequate free space.

It is helpful if you can provide the output of inxi -Fzxx (as pre-formatted text using the </> button from the top of the text input window). This provides OS and file system details that may help plan repairs.