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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31768128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:30:40  来源:igfitidea点击:

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

pythonmacosinstallationpiposx-mavericks

提问by Mona Jalal

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?

我不知道这是怎么回事,但我坚持遵循一些无处可去的 stackoverflow 解决方案。你能帮我解决这个问题吗?

  Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py
    The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
    The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
    /tmp/tmpbSjX8k/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
    Collecting pip
      Downloading pip-7.1.0-py2.py3-none-any.whl (1.1MB)
        100% |████████████████████████████████| 1.1MB 181kB/s 
    Installing collected packages: pip
      Found existing installation: pip 1.4.1
        Uninstalling pip-1.4.1:
          Successfully uninstalled pip-1.4.1
    Successfully installed pip-7.1.0
    Monas-MacBook-Pro:CS764 mona$ pip --version
    -bash: /usr/local/bin/pip: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory

采纳答案by LancDec

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

我曾使用 home-brew 在 OS X 10.10 上安装 2.7,但新安装缺少符号链接。我跑了

brew link --overwrite python

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

如何在 Homebrew 中对 python 进行符号链接中所述?它解决了这个问题。

回答by Steven Kryskalla

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

我猜你有两个 python 安装,或两个 pip 安装,其中一个已被部分删除。

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").

你为什么使用sudo?理想情况下,您应该能够从您的用户帐户而不是使用 root 安装和运行所有内容。如果您将 root 和您的本地帐户混合在一起,您更有可能遇到权限问题(例如,请参阅它给出的关于“当前用户不拥有父目录”的警告)。

What do you get if you run this?

如果你运行这个,你会得到什么?

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

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

这将显示您pip尝试使用哪个 python 二进制文件。如果它指向/usr/local/opt/python/bin/python2.7,然后尝试运行这个:

$ 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.

如果显示“没有这样的文件或目录”,则 pip 正在尝试使用已删除的 python 二进制文件。

Next, try this:

接下来,试试这个:

$ which python
$ which python2.7

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

查看实际工作的python二进制文件的路径。

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

因为它看起来像PIP已成功安装的地方,这可能是因为/usr/local/bin/pip是较旧的安装PIP的那是在上涨的一部分PATH。为了测试这一点,您可以尝试pip像这样将无法运行的二进制文件移开(可能需要sudo):

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

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

然后pip --version再次尝试运行您的命令。希望它选择正确的版本并成功运行。

回答by sahar

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

我有类似的问题。基本上 pip 正在寻找错误的路径(旧安装路径)或 python。以下解决方案对我有用:

  • I checked where the python path is (try which python)
  • I checked the first line on the pip file (/usr/local/bin/pip2.7and /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.
  • 我检查了 python 路径在哪里(尝试which python
  • 我检查了 pip 文件(/usr/local/bin/pip2.7/usr/local/bin/pip)的第一行。该行应说明 python 路径的正确路径。就我而言,没有。我纠正了它,现在它工作正常。

回答by DaveSaunders

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

我使用 sudo 进行安装时犯了同样的错误。(哎呀)

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

This brought everything back to normal.

这让一切都恢复了正常。

回答by Jordan

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

如果它对任何人有帮助,当 pip 在升级后今天停止工作时,另一个问题中提到的解决方案对我有用:升级后 Pip 损坏

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

当先前缓存的位置更改时,这似乎是一个问题,因此您可以使用以下命令刷新缓存:

hash -r

回答by Simon

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.

就我而言,我决定从我的 mac 中删除 homebrew python 安装,因为我已经通过 MacPorts 在我的 mac 上安装了另外两个版本的 python。这导致了错误消息。

Reinstalling python through brew solved my issue.

通过 brew 重新安装 python 解决了我的问题。

回答by yabrol

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

我遇到过同样的问题。我安装了 Python 2.7 和 3.6。Python 2.7 可以virtualenv正常工作,但是在安装 Python3 后,virtualenv 一直在寻找 2.7 版本并找不到它。正在pip install virtualenv安装 Python3 版本的 virtualenv。

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

然后,对于每个命令,如果我想使用 Python2,我会使用 virtualenv --python=python2.7 somecommand

回答by feuyeux

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

为了简化操作,我们可以使用以下命令重新安装版本2:

brew install python@2

brew install python@2

Then on my mac, it looks as below:

然后在我的 mac 上,它看起来如下:

? 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)

回答by user9022502

sudo /usr/bin/easy_install pip

this command worked out for me

这个命令对我有用

回答by Peter. Chen

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.

我遇到了同样的问题。如果我跑brew link --overwrite python2. 还是有的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.

解决了!现在我们可以使用 python2 版本的结构了。

=== 2018/07/25 updated

=== 2018/07/25 更新

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

当您的 os python 链接到 python3 时,有一种方便的方法可以使用 python2 版本 fab。.sh为您的命令。

# 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.

希望这可以帮助。