I was getting this error when I was running Python 3.13 but the Azure Function was running as 3.12. The following fixed it for me:
deactivate rm -rf .venv python3.12 -m venv .venv