One solution would be to add the parameter --break-system-packages to pip.
Another solution is to rename file /usr/lib/python{{ version }}/EXTERNALLY-MANAGED:
sudo mv /usr/lib/python3.11/EXTERNALLY-MANAGED /usr/lib/python3.11/EXTERNALLY-MANAGED.old