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

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

    To simplify to operation, we can use the below command to reinstall version 2:

    brew install python@2

    Then on my mac, it looks as below:

    ▶ python -V
    Python 2.7.10
    
    ▶ python2 -V
    Python 2.7.14
    
    ▶ python3 -V
    Python 3.6.5
    
    ▶ pip2 -V
    pip 9.0.3 from /usr/local/lib/python2.7/site-packages (python 2.7)
    
    ▶ pip3 -V
    pip 9.0.3 from /usr/local/lib/python3.6/site-packages (python 3.6)
    
    ▶ pip --version
    pip 9.0.3 from /usr/local/lib/python2.7/site-packages (python 2.7)
    
    0 讨论(0)
  • 2020-11-28 20:34

    I had the same issue, virtualenv was pointing to an old python path. Fixing the path resolved the issue:

    $ virtualenv -p python2.7 env
    -bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
    
    $ which python2.7
    /opt/local/bin/python2.7
    
    # needed to change to correct python path
    $ head  /usr/local/bin/virtualenv
    #!/usr/local/opt/python/bin/python2.7 <<<< REMOVED THIS LINE
    #!/opt/local/bin/python2.7 <<<<< REPLACED WITH CORRECT PATH
    
    # now it works:
    $ virtualenv -p python2.7 env
    Running virtualenv with interpreter /opt/local/bin/python2.7
    New python executable in env/bin/python
    Installing setuptools, pip...done.
    
    0 讨论(0)
  • 2020-11-28 20:36

    I got same problem. If I run brew link --overwrite python2. There was still zsh: /usr/local/bin//fab: bad interpreter: /usr/local/opt/python/bin/python2.7: no such file or directory.

    cd /usr/local/opt/
    mv python2 python
    

    Solved it! Now we can use python2 version fabric.

    === 2018/07/25 updated

    There is convinient way to use python2 version fab when your os python linked to python3. .sh for your command.

    # fab python2
    cd /usr/local/opt
    rm python
    ln -s python2 python
    
    # use the fab cli
    ...
    
    # link to python3
    cd /usr/local/opt
    rm python
    ln -s python3 python
    

    Hope this helps.

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

    I had similar issue. Basically pip was looking in a wrong path (old installation path) or python. The following solution worked for me:

    • I checked where the python path is (try which python)
    • I checked the first line on the pip file (/usr/local/bin/pip2.7 and /usr/local/bin/pip). The line should state the correct path to the python path. In my case, didn't. I corrected it and now it works fine.
    0 讨论(0)
  • 2020-11-28 20:43

    I made the same error using sudo for my installation. (oops)

    brew install python
    brew linkapps python
    brew link --overwrite python 
    

    This brought everything back to normal.

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

    I had the same issue. I have both Python 2.7 & 3.6 installed. Python 2.7 had virtualenv working, but after installing Python3, virtualenv kept looking for version 2.7 and couldn't find it. Doing pip install virtualenv installed the Python3 version of virtualenv.

    Then, for each command, if I want to use Python2, I would use virtualenv --python=python2.7 somecommand

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