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

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

    Fixing pip

    For this error:

    ~/Library/Python/2.7/bin/pip: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory`
    

    The source of this problem is a bad python path hardcoded in pip (which means it won't be fixed by e.g. changing your $PATH). That path is no longer hardcoded in the lastest version of pip, so a solution which should work is:

    pip install --upgrade pip
    

    But of course, this command uses pip, so it fails with the same error.

    The way to bootstrap yourself out of this mess:

    1. Run which pip
    2. Open that file in a text editor
    3. Change the first line from #!/usr/local/opt/python/bin/python2.7 to e.g. #!/usr/local/opt/python2/bin/python2.7 (note the python2 in the path), or any path to a working python interpreter on your machine.
    4. Now, pip install --upgrade pip (this overwrites your hack and gets pip working at the latest version, where the interpreter issue should be fixed)

    Fixing virtualenv

    For me, I found this issue by first having the identical issue from virtualenv:

    ~/Library/Python/2.7/bin/virtualenv: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory`
    

    The solution here is to run

    pip uninstall virtualenv
    pip install virtualenv
    

    If running that command gives the same error from pip, see above.

提交回复
热议问题