ModuleNotFoundError: No module named 'PIL'
python -m pip install Pillow
Not pip install PIL, which installs nothing useful, and not pip install pil.
PIL was the original library and stopped in 2011. Pillow forked it and kept the same import name so existing code would keep working. The distribution is Pillow, the package is PIL. That mismatch has confused people for fifteen years.
You almost certainly have more than one Python, and you installed into a different one. Use the interpreter itself to install:
python -m pip install Pillow
import sys
print(sys.executable)
Run that print inside the program that fails. If it does not match the Python you installed into, that is your answer.
python -m venv .venv
source .venv/bin/activate
python -m pip install Pillow
On Windows the activate line is .venv\Scripts\activate. Your editor may also need telling which interpreter to use, which is a common cause of code that runs in the terminal but not in the IDE.
%pip install Pillow
The magic installs into the kernel actually running the notebook, which a plain shell command does not always do.
The PIL to Pillow converter finds most of these automatically, and the other error pages cover the rest.