Python 另一个`bash: pip: command not found`

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40774324/
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 23:58:58  来源:igfitidea点击:

Yet another `bash: pip: command not found`

pythondebianpip

提问by RolfBly

Lots of installation instructions tell you to do pip install [package]. But in my case that won't work, it'll say -bash: pip: command not found

很多安装说明都告诉你去做pip install [package]。但在我的情况下,这行不通,它会说-bash: pip: command not found

python pip install [package]works OK. Likewise for easy_install, won't run by itself, will run when started with python.

python pip install [package]工作正常。同样 for easy_install,不会自己运行,会在用 python 启动时运行。

I'm confused as to how it shouldwork. Pip is no executable, there's no module called pip.py, there's only <path>\pip\__init__.py. So if pip install [package]is to work properly, the bash shell must understand when to act as a python interpreter. Which it doesn't.

我对它应该如何工作感到困惑。Pip 没有可执行文件,没有名为 pip.py 的模块,只有<path>\pip\__init__.py. 因此,如果pip install [package]要正常工作,bash shell 必须了解何时充当 python 解释器。它没有。

I don't believe all those install instructions are off. So I must be missing something. What?

我不相信所有这些安装说明都已关闭。所以我一定错过了一些东西。什么?

Thisdidn't help, nor did this, in fact trying sudo apt-get install python-pipled to what I think is an unresolved bug. So I had to revert to this solution, to get me a somewhat working pip. (Now read again from the top).

并没有帮助,也没有这个,事实上是在试图sudo apt-get install python-pip引发了什么,我认为是一个未解决的bug。所以我不得不恢复到这个解决方案,让我得到一个有点工作的点子。(现在从顶部再次阅读)。

Edit: Python 2.7. Not 3.x.

编辑:Python 2.7。不是 3.x。

回答by Hong

Most packages, including Debian's package, adds a /usr/bin/pip(or pip3, see below). See: https://packages.debian.org/jessie/all/python-pip/filelist

大多数软件包,包括 Debian 的软件包,都会添加一个/usr/bin/pip(或pip3,见下文)。请参阅:https: //packages.debian.org/jessie/all/python-pip/filelist

I thinkthe pip installer via get-pip.py also does this.

认为通过 get-pip.py 的 pip 安装程序也可以这样做。

The file basically relays it through python via console_scripts.

该文件基本上通过console_scripts通过python中继它。

Check your /usr/bin and /usr/local/bin for pip. (if you installed pip outside of a package manager or without root/sudo then they probably don't exist). But they should...

检查您的 /usr/bin 和 /usr/local/bin 是否有 pip。(如果你在包管理器之外安装了 pip 或者没有 root/sudo 那么它们可能不存在)。但是他们应该...

If you're on python3, the file might be named pip3 so check /usr/bin and /usr/local/bin for that instead.

如果您使用的是 python3,则该文件可能被命名为 pip3,因此请改为检查 /usr/bin 和 /usr/local/bin。

You can add an entry to your .bash_aliases to alias if you want the shortcut:

如果需要快捷方式,您可以在 .bash_aliases 中添加一个条目到别名:

alias pip='pip3'
# or
# alias pip='python pip'

回答by RolfBly

Attempts to re-install or fix failed. So I removed pip completely and did what I hope is a clean install. First:

尝试重新安装或修复失败。所以我完全删除了 pip 并做了我希望的全新安装。第一的:

sudo apt-get remove --auto-remove python-pip 

Then delete pips caches and existing downloads, where appropriate (in my case, I left still working pipsinside virtual environments alone):

然后在适当的情况下删除 pips 缓存和现有下载(在我的情况下,我仍然pips单独在虚拟环境中工作):

sudo find / -type d -name 'pip*'
sudo rm -rf <dirname>

Then download the official pip installer and install it:

然后下载官方的pip安装程序并安装:

wget https://bootstrap.pypa.io/get-pip.py 
sudo python get-pip.py  

Now pip freezeruns without errors. In addition:

现在pip freeze运行没有错误。此外:

  • the cause was that the pip-script was gone. After the re-install, it's there again: /usr/local/bin/pip. So what I thought:

    the bash shell must understand when to act as a python interpreter. Which it doesn't.

    is not right. The shell willlaunch a python script, if its shebang-line points to the proper interpreter. Learning all the time...

  • many sources suggest to sudo apt-get install python-pip. That's wrong. apt-getis several versions behind the current stable one. Mixing versions leads to all sorts of errors.

  • 原因是 pip 脚本消失了。重新安装后,它又出现了:/usr/local/bin/pip。所以我的想法是:

    bash shell 必须了解何时充当 python 解释器。它没有。

    是不正确的。shell启动一个 python 脚本,如果它的 shebang-line 指向正确的解释器。一直在学习...

  • 许多消息来源建议sudo apt-get install python-pip。那是错误的。apt-get是当前稳定版本后面的几个版本。混合版本会导致各种错误。

回答by Saif Siddiqui

use python3 -m pip install Xwhere X is the package name like if I want to install Pillow Python Imaging Library is will use

使用python3 -m pip install X其中 X 是包名称,就像我想安装 Pillow Python Imaging Library 一样将使用

python3 -m pip install Pillow