which can be overriding some things from Homebrew’s Python, breaking it.
It looks like you are somehow making code from Pip 3 run in Python 2 environment – which isn’t supposed to work.
Check carefully what exact script is being run with travis_retry pip install --upgrade pip and what Python executable and sys.path it gets. (Optionally fixing your code to properly run pip2 before that.)