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

后端 未结 19 1055
再見小時候
再見小時候 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:21

    Editing the first line of this file worked to me:

    MBP-de-Jose:~ josejunior$ which python3

    /usr/local/Cellar/python/3.7.3/bin/python3
    

    MBP-de-Jose:~ josejunior$

    before

    #!/usr/local/opt/python/bin/python3.7
    

    after

    #!/usr/local/Cellar/python/3.7.3/bin/python3
    
    0 讨论(0)
  • 2020-11-28 20:23

    In my case, I decided to remove the homebrew python installation from my mac as I already had two other versions of python installed on my mac through MacPorts. This caused the error message.

    Reinstalling python through brew solved my issue.

    0 讨论(0)
  • 2020-11-28 20:23

    For me, on centOS 7 I had to remove the old pip link from /bin by

    rm /bin/pip2.7 
    rm /bin/pip
    

    then relink it with

    sudo ln -s  /usr/local/bin/pip2.7 /bin/pip2.7
    

    Then if

    /usr/local/bin/pip2.7
    

    Works, this should work

    0 讨论(0)
  • 2020-11-28 20:24

    All you need to do is... close the terminal window and reopen new one to fix this issue.

    The issue is, new python path is not added to bashrc(Either source or new terminal window would help).

    0 讨论(0)
  • 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
    0 讨论(0)
  • 2020-11-28 20:25

    Because I had both python 2 and 3 installed on Mac OSX I was having all sorts of errors.

    I used which to find the location of my python2.7 file (/usr/local/bin/python2.7)

    which python2.7
    

    Then I symlinked my real python2.7 install location with the one the script expected:

    ln -s /usr/local/bin/python2.7 /usr/local/opt/python/bin/python2.7
    
    0 讨论(0)
提交回复
热议问题