7

PROBLEM DESCRIPTION

I'm setting up a new MacBook and decided to jump too fast into downloading Python 3.8. I downloaded it from the website https://www.python.org/ before realizing it's better practice to do so with homebrew.

GOAL - Remove Python 3.8 from my PATH to later install with Homebrew

I cleared Python 3.8 from my filesystem thanks to this page https://nektony.com/how-to/uninstall-python-on-mac, but the path the Version 3.8 is still in my PATH variable.

Typing echo $PATH in my terminal (zsh) returns /Library/Frameworks/Python.framework/Versions/3.8/bin along with other paths. Does anyone know how I can remove this path? It no longer exists in my filesystem so it's pointing to nothing.

WHAT I HAVE TRIED

I have checked all the following files using nano and they all do not have the export command which would place it in the path in the first place.

Files checked: /etc/profile /etc/bashrc ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc

MY ENV

I am running a macbook pro with Catalina (10.15.4) and using zsh as my terminal.

Any help is appreciated, thanks a lot!!

Matt
  • 233
  • 1
  • 2
  • 12
  • One other suggestion is that you just don't need to worry about the system python version since brew is going to install another standalone python. Further, shell will look for the python command in the directories in `PATH` one by one and the one installed by brew is going to take precedence. – cicolus May 26 '20 at 22:11
  • 1
    Does this answer your question? [How to remove entry from $PATH on mac](https://stackoverflow.com/questions/15872666/how-to-remove-entry-from-path-on-mac) – cicolus May 26 '20 at 22:12
  • @cicolus Homebrew will take precedence but I'm still trying to avoid having an extra path in my PATH variable that doesn't need to be there. The question you referred me to does answer the question, but I'm looking for an alternate solution where I don't need to "hardcode" my path into my bash/zsh profile. Lmk if you know what I mean! – Matt May 26 '20 at 22:24
  • Have you tried the answer I provided below? Also worthy of notice is the `/etc/profile` file you might want to take a look at. In the worst case you can do a system wide `grep` on the path you are looking for and remove it from the relevant places. – cicolus May 26 '20 at 22:45

3 Answers3

11

Found the solution! Through running grep {subset of the path you're trying to remove} . (don't forget the period at the end), I found all places where that path was found on my computer. That brought me to seeing that the ./.zprofile file was exporting the Python 3.8 path. I removed it from that file, saved it and restarted my Terminal. Now, the path is gone and I am happy

Matt
  • 233
  • 1
  • 2
  • 12
0

If you check what is stored in each variable using the set command, you might see Python somewhere there. To check what's in there, type set > ~/Documents/set.txt to view the contents. You can then open set.txt in your Documents directory to see the contents. Then, if you go back to Terminal, you can type PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin or whatever you would like to set it to. In conclusion, all you need to use is the PATH=<desired path> to set the value.

Todd
  • 500
  • 4
  • 10
  • Thanks @Todd! Didn't know you could print out each variable like that, pretty cool. I've tried typing `PATH=/user/local/.....`, but the issue with this is that my path goes back to having the python version as soon as I quit my terminal session – Matt May 26 '20 at 22:29
  • Hmmmm...That’s odd. Can you reinstall python and this time uninstall using the uninstalled package to make sure all traces are removed? Try reinstalling from the Python website. – Todd May 26 '20 at 22:32
  • Also, you can try disabling SIP from macOS Recovery and then trying the above commands. SIP might prevent you from making the desired changes. – Todd May 26 '20 at 22:36
  • Sorry I don't understand what you mean by reinstalling and uninstalling from the Python website. And from other research to find a solution, it seems like changing the path like that only edits the current session and unfortunately does not change it for good – Matt May 26 '20 at 23:07
  • Hmm...It permanently changed for me. Have you tried disabling SIP? I meant that you should Install python from its website the uninstall using the uninstaller package. – Todd May 26 '20 at 23:08
  • Not too familiar with SIP and have read that it should be kept as last resort, so I'll try a few other things and keep that for later if I really need to! I was not aware that there is an uninstaller package! I'll go look into that right now and let you know how it goes – Matt May 26 '20 at 23:12
  • Great! All macOS applications have a proper way to uninstall. It’s basically the installer but it uninstalls the app files. – Todd May 26 '20 at 23:13
  • Thanks @Todd! Where do I find this uninstaller? I checked the package that gets downloaded when installing python (`python-3.8.3-macosx10.9.pkg`) but didn't see anywhere to uninstall – Matt May 26 '20 at 23:15
  • Is there no uninstall option? Usually choosing the uninstall option will run the uninstaller. – Todd May 26 '20 at 23:16
  • With the installer package, there's 5 steps to it -> Introduction, Read Me, License, Destination Select, Installation Type, Installation and Summary. The first time going through the flow I remember not seeing an uninstaller option. Have you ever seen one? Might've missed it! – Matt May 26 '20 at 23:19
  • Can you try typing Uninstall Python in Spotlight Search? – Todd May 26 '20 at 23:19
  • Hmm nothing unfortunately. A bit trickier than expected! – Matt May 26 '20 at 23:23
0

Check /etc/paths and /etc/paths.d/* and remove the relevant paths.

cicolus
  • 697
  • 5
  • 16