Why is pip3 referencing Python 2 instead of 3?
Run
open /usr/bin/pip3 -a Textedit.app

Or general:
open $(which pip3) -a Textedit.app

The first line (shebang) would be point to python 2. Fix it by putting in the path to python 3 there.
I use conda environment, so for me it is:
#!/usr/local/opt/python@3.8/bin/python3.8

For you, it should be
#!/usr/bin/python3 

or any other python executable that you want to use.

Alternate method is running pip by invoking python3.
python3 -m pip install xattr


https://stackoverflow.com/a/51055589/