pip安装/usr/local/opt/python/bin/python2.7:错误的解释器:没有这样的文件或目录

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (4016)

我不知道这笔交易是什么,但我坚持遵循一些无处可去的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
提问于
用户回答回答于

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

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

如果你跑这个怎么办?

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

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

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

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

接下来,试试这个:

$ which python
$ which python2.7

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

由于看起来pip已成功安装在某个地方,因此它可能是/usr/local/bin/pip较旧的pip安装的一部分PATH。要测试它,您可以尝试移动不起作用的pip二进制文件,如下所示(可能需要sudo):

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

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

用户回答回答于

我使用sudo为我的安装犯了同样的错误。(糟糕)

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

这使一切恢复正常。

扫码关注云+社区

领取腾讯云代金券