Search code examples
pythonpython-3.xmacoshomebrewunlink

Problems with unlinking python using homebrew


I want to uninstall python from my Mac since I have some troubles with it and want to reinstall it.

Thus, I've tried to use brew unlink python. However, the console throws the following error, when I try that:

Unlinking /usr/local/Cellar/python/3.7.4... Error: No such file or directory @ realpath_rec - /usr/local/opt/python

Now I'm not able to use python due to the mentioned troubles, but I'm not able to reinstall it either. What can I do?


Solution

  • The symlink appears to be missing. Reproduced:

    % rm /usr/local/opt/python
    rm: remove symbolic link '/usr/local/opt/python'? y
    
    % brew unlink python
    Unlinking /usr/local/Cellar/python/3.7.4... Error: No such file or directory @ realpath_rec - /usr/local/opt/python
    
    % brew reinstall  --force python
    ==> Reinstalling python
    Error: python 3.7.4 is already installed
    To install 3.7.4, first run `brew unlink python`.
    

    Recreate the link...

    % ln -s /usr/local/Cellar/python/3.7.4/bin/python3 /usr/local/opt/python
    '/usr/local/opt/python' -> '/usr/local/Cellar/python/3.7.4/bin/python3'
    

    and you should be able to unlink or uninstall:

    % brew unlink python
    Unlinking /usr/local/Cellar/python/3.7.4... 22 symlinks removed
    
    % brew uninstall python
    Uninstalling /usr/local/Cellar/python/3.7.4... (3,865 files, 60MB)