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

后端 未结 19 1058
再見小時候
再見小時候 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.

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

    I'm guessing you have two python installs, or two pip installs, one of which has been partially removed.

    Why do you use sudo? Ideally you should be able to install and run everything from your user account instead of using root. If you mix root and your local account together you are more likely to run into permissions issues (e.g. see the warning it gives about "parent directory is not owned by the current user").

    What do you get if you run this?

    $ head -n1 /usr/local/bin/pip
    

    This will show you which python binary pip is trying to use. If it's pointing /usr/local/opt/python/bin/python2.7, then try running this:

    $ ls -al /usr/local/opt/python/bin/python2.7
    

    If this says "No such file or directory", then pip is trying to use a python binary that has been removed.

    Next, try this:

    $ which python
    $ which python2.7
    

    To see the path of the python binary that's actually working.

    Since it looks like pip was successfully installed somewhere, it could be that /usr/local/bin/pip is part of an older installation of pip that's higher up on the PATH. To test that, you may try moving the non-functioning pip binary out of the way like this (might require sudo):

    $ mv /usr/local/bin/pip /usr/local/bin/pip.old
    

    Then try running your pip --version command again. Hopefully it picks up the correct version and runs successfully.

    0 讨论(0)
  • 2020-11-28 20:30
    sudo /usr/bin/easy_install pip
    

    this command worked out for me

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

    You could have two different versions of Python and pip.

    Try to:

    pip2 install --upgrade pip and then pip2 install -r requirements.txt

    Or pip3 if you are on newer Python version.

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

    I had used home-brew to install 2.7 on OS X 10.10 and the new install was missing the sym links. I ran

    brew link --overwrite python
    

    as mentioned in How to symlink python in Homebrew? and it solved the problem.

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

    In case it helps anyone, the solution mentioned in this other question worked for me when pip stopped working today after upgrading it: Pip broken after upgrading

    It seems that it's an issue when a previously cached location changes, so you can refresh the cache with this command:

    hash -r
    
    0 讨论(0)
提交回复
热议问题