pip installation /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory

后端 未结 19 1156
再見小時候
再見小時候 2020-11-28 19:58

I don\'t know what\'s the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this?

  Monas-MacBook-Pro:         


        
19条回答
  •  盖世英雄少女心
    2020-11-28 20:24

    TLDR: pip found in your path a is a symlink and the referenced location no longer contains the executable. You need to update the symlink.

    It helps to understand a couple of things.

    • When you type something like python or pip you os will search /etc/paths to try to find the associated executable for that command. You can see everything in there by using cat /etc/paths.
    • To determine the location of the executable that your shell will use there is a handy command which, you can type which python or which pip. This will tell you the location of the executable that your shell will use for that command.
    • This part is key. The location may or may not be an actual executable, it could be a symbolic link (symlink).
    • Its common for /etc/paths to contain /usr/local/bin, its also common for /usr/local/bin to be a bunch of symlinks to the actual executables. Not the executables themselves.
    • If the executable at the symlinks referenced location doesn't exist you will get an error like bad interpreter: No such file or directory

    With that being said the problem is likely that pip is a symlink and the linked executable probably doesn't exist at that location anymore. To fix it do the following

    1. Find the location of the executable - which pip (gives something like this /usr/local/bin/pip)
    2. Check the symlink reference location ls -l /usr/local/bin/pip | grep pip (give something like this pip -> /usr/local/opt/python@3.7/bin/pip3)
    3. Check if the executable exists at the referenced location ls /usr/local/opt/python@3.7/bin/pip3 (you are having this issue so it probably doesn't).
    4. Remove the old symlink rm -r /usr/local/bin/pip
    5. Find the actual pip executable if using homebrew it will be in /usr/local/opt you can use something like ls /usr/local/opt/ | grep python to find it.
    6. Add the right symlink for the pip executable. ln -s /usr/local/opt/python@3.7/bin/pip3 /usr/local/bin/pip

提交回复
热议问题