Trying to untangle my python mess

Hoping to just uninstall all of my Homebrew Python installs and start over. I am mainly now using Python to run PyTorch , so I’ve installed Anaconda and hope to use PyTorch with it, however I seem (in addition to the Mac OS X default 2.7 Python decrepitude) to have a number of other Homebrew versions of Python I’d like to remove. Here’s what I’ve done/tried so far–happy to just get rid of all of this and start over, ideally without destabilizing all the other packages I have installed as well–and this describes the state of my installs so far and attempts to uninstall as well:

$ echo $PATH
/Users/myusername/.cargo/bin:/usr/local/opt/llvm@7/bin:/Users/myusername/.cargo/bin:/usr/local/sbin:/usr/local/bin:/opt/homebrew/bin:/Users/myusername/.cargo/bin:/usr/local/sbin:/usr/local/bin:/opt/homebrew/bin:/Users/myusername/.rvm/gems/ruby-2.6.3/bin:/Users/myusername/.rvm/gems/ruby-2.6.3@global/bin:/Users/myusername/.rvm/rubies/ruby-2.6.3/bin:/Users/myusername/anaconda3/bin:/Users/myusername/.cargo/bin:/usr/local/sbin:/usr/local/bin:/opt/homebrew/bin:/opt/facebook/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/opt/facebook/bin/biggrep:/opt/facebook/nuclide/latest/nuclide/pkg/fb-on-demand-cli/bin:/opt/facebook/ops/scripts/chef:/opt/homebrew/bin:/usr/local/munki:/opt/facebook/hg/bin:/Users/myusername/.rvm/bin

$ brew config
HOMEBREW_VERSION: 2.1.8
ORIGIN: https://github.com/Homebrew/brew
HEAD: 549a40bedb32171912a449d8d0e7bcae02d5b432
Last commit: 6 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 46d20bdd1a21b27008cca01cfc87322b50283aab
Core tap last commit: 25 hours ago
HOMEBREW_PREFIX: /usr/local
CPU: quad-core 64-bit kabylake
Homebrew Ruby: 2.3.7 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Clang: 10.0 build 1001
Git: 2.20.1 => /usr/local/bin/git
Curl: 7.54.0 => /usr/bin/curl
macOS: 10.14.5-x86_64
CLT: 10.3.0.0.1.1562985497
Xcode: N/A

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don’t worry or file an issue; just ignore this. Thanks!

Warning: “config” scripts exist outside your system or Homebrew directories.
./configure scripts often look for *-config scripts to determine if
software packages are installed, and which additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew-provided
script of the same name. We found the following “config” scripts:
/opt/homebrew/bin/pkg-config
/opt/homebrew/bin/python2-config
/opt/homebrew/bin/python3.6m-config
/opt/homebrew/bin/python3.7-config
/opt/homebrew/bin/python2.7-config
/opt/homebrew/bin/python3.7m-config
/opt/homebrew/bin/ksba-config
/opt/homebrew/bin/python-config
/opt/homebrew/bin/libassuan-config
/opt/homebrew/bin/pcre2-config
/opt/homebrew/bin/gpg-error-config
/opt/homebrew/bin/python3.6-config
/opt/homebrew/bin/libgcrypt-config
/opt/homebrew/bin/pth-config
/Users/myusername/anaconda3/bin/icu-config
/Users/myusername/anaconda3/bin/krb5-config
/Users/myusername/anaconda3/bin/freetype-config
/Users/myusername/anaconda3/bin/xslt-config
/Users/myusername/anaconda3/bin/libpng16-config
/Users/myusername/anaconda3/bin/python3.7-config
/Users/myusername/anaconda3/bin/libpng-config
/Users/myusername/anaconda3/bin/xml2-config
/Users/myusername/anaconda3/bin/python3.7m-config
/Users/myusername/anaconda3/bin/python3-config
/Users/myusername/anaconda3/bin/curl-config
/Users/myusername/anaconda3/bin/ncursesw6-config
/Users/myusername/anaconda3/bin/pcre-config

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn’t put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libiperf.0.dylib
/usr/local/lib/libjson-c.2.dylib
/usr/local/lib/libykpers-1.1.dylib
/usr/local/lib/libyubikey.0.dylib
/usr/local/lib/libyubikey.dylib

Warning: Unbrewed header files were found in /usr/local/include.
If you didn’t put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected header files:
/usr/local/include/iperf_api.h

Warning: Unbrewed .la files were found in /usr/local/lib.
If you didn’t put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .la files:
/usr/local/lib/libiperf.la

Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn’t put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
/usr/local/lib/libiperf.a
/usr/local/lib/libyubikey.a

$brew cleanup

Warning: Skipping cmake: most recent version 3.15.1 not installed
Warning: Skipping git: most recent version 2.22.0_1 not installed
Warning: Skipping pcre2: most recent version 10.33 not installed

$ which python
/opt/homebrew/bin/python

$ which python2.7
/opt/homebrew/bin/python2.7

$ which python3
/usr/local/bin/python3

$ which python3.7
/opt/homebrew/bin/python3.7

$ python --version
Python 2.7.10

$ ll /opt/homebrew/bin/py
pydoc python python2.7-config python3.6m-config pythonw
pydoc2 python-config python3 python3.7 pythonw2
pydoc2.7 python2 python3.6 python3.7-config pythonw2.7
pydoc3.6 python2-config python3.6-config python3.7m pyvenv-3.6
pydoc3.7 python2.7 python3.6m python3.7m-config pyvenv-3.7

$ brew uninstall python
Error: No such keg: /usr/local/Cellar/python

$ pip --version
-bash: /opt/homebrew/bin/pip: /opt/homebrew/opt/python35/bin/python3.5: bad interpreter: No such file or directory

$ brew link --overwrite python
Warning: Already linked: /usr/local/Cellar/python/3.7.4
To relink: brew unlink python && brew link python

$ brew link --overwrite python
Error: No such keg: /usr/local/Cellar/python

$ brew link --overwrite python3.7
Error: No such keg: /usr/local/Cellar/python3.7

$ head -n1 /usr/local/bin/pip
head: /usr/local/bin/pip: No such file or directory

$ head -n1 /usr/local/bin/pip3 # one time I ran it:
#!/usr/local/opt/python/bin/python3.7

$ head -n1 /usr/local/bin/pip3 # now, when I run it:
head: /usr/local/bin/pip3: No such file or directory

$ brew uninstall pip3
Error: No such keg: /usr/local/Cellar/pip3

$ head -n1 /usr/local/bin/pip3.7 # one time when I ran it:
#!/usr/local/opt/python/bin/python3.7

$ head -n1 /usr/local/bin/pip3.7 # now, when I run it:
head: /usr/local/bin/pip3.7: No such file or directory

$ ll /System/Library/Frameworks/Python.framework/
total 0
lrwxr-xr-x 1 root wheel 23 Oct 30 2018 Python@ -> Versions/Current/Python
lrwxr-xr-x 1 root wheel 26 Oct 30 2018 Resources@ -> Versions/Current/Resources
drwxr-xr-x 7 root wheel 224 Oct 30 2018 Versions/
drwxr-xr-x 3 root wheel 96 Jul 8 17:07 Modules/
drwxr-xr-x 3 root wheel 96 Jul 8 17:07 Examples/
lrwxr-xr-x 1 root wheel 24 Jul 26 16:50 Headers@ -> Versions/Current/Headers
drwxr-xr-x 151 root wheel 4832 Jul 26 16:50 …/
drwxr-xr-x 8 root wheel 256 Jul 26 16:50 ./

$ ls -l /usr/local/bin/python*
lrwxr-xr-x 1 root wheel 25 Jul 27 12:32 /usr/local/bin/python3 -> /opt/homebrew/bin/python3

Yikes!
I’m certain that a few of the above commands are erroneously run and are definitely just guesses of what to try by me, so feel free to correct and/or tell me what to try.
Thank you kindly.

Ouch! D@#n you’ve kind of borked your system python. You’ve got quite a few ownership changes to ‘root’ for files/directories that originally didn’t have them, for example; ‘/usr/local/bin’. Don’t know what you did to install to ‘/opt/’ though. This could possibly be reverted but I’m thinking there’s less time in just doing a OS system repair which would leave personal apps/files intact. You could try unlinking, cleaning up with brew, and removing known files that you specifically knew shouldn’t be in particular directories before reinstalling macOS. My suggestion is just install python with a version manager such as ‘pyenv’ after you get this resolved.