Hello and welcome,
Could you try these steps and let us know how it goes (they involve setting up a virtual environment)?
In the terminal (assuming mac or linux - see here for windows):
python -m venv my_env
source my_env/bin/activate
pip3 install anvil-uplink
python
In python shell:
import anvil.server
anvil.server.connect("<your uplink key goes here>")
Side note: You can format your code on the forum by following these instructions.