CUDA/GCC problem when building from source

I get the following error message when trying to build PyTorch:

unsupported GNU version! gcc versions later than 8 are not supported!

According to this stackoverflow thread I need to make sure that I use the max supported GCC version for the CUDA version I have installed.

nvidia-smi

gives me

NVIDIA-SMI 460.32.03    Driver Version: 460.32.03    CUDA Version: 11.2

and

gcc --version

gives me

gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

and

nvcc -V

gives

Cuda compilation tools, release 11.2, V11.2.152

According to the thread linked above, CUDA 11 supports GCC <= 10.
What am I missing here?

For some reason, it worked after I tried building inside an Anaconda environment instead of a venv virtual-environment. I do not know why.