我下载了pip并运行python setup.py install,一切正常。本教程的下一步是运行pip install <lib,你想要>,但在它尝试在线查找任何东西之前,我得到一个错误“bash: pip: command not found”。

这是在Mac OS x上,我假设在运行setup。py时,某种路径设置没有正确设置。我如何进一步调查?我需要检查什么才能更好地了解问题的确切原因?

编辑:我还尝试了为Mac安装Python 2.7,希望友好的安装过程会做一些管理工作,比如编辑PATH和任何其他需要发生的事情,以便根据教程工作,但这并不管用。安装后,运行'python'仍然运行python 2.6, PATH没有更新。


当前回答

最新更新2021年。

在Ubuntu 20中,64bit工作得很完美

安装python3

Sudo apt安装python3

Pip安装

Sudo安装python3-pip

在$HOME/中添加以下别名。Bash_aliases在某些情况下文件可能被隐藏。

别名pip="/usr/bin/python3 -m pip "

刷新当前终端会话。

. ~ / . profile

检查PIP使用情况:PIP 安装软件包:pip Install {{package_name}}

额外的信息

获取Home路径

echo $ HOME

您将得到您的主路径。

其他回答

安装Homebrew,打开终端或你最喜欢的OSX终端模拟器并运行

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

在PATH环境变量的顶部插入Homebrew目录。您可以通过在~/的底部添加下面的行来做到这一点。概要文件

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

现在,我们可以安装Python 2.7:

$ brew install python

获取pip存储库:

$ git clone https://github.com/pypa/pip

pip安装:

$sudo easy_install pip

2020年更新:

对于当前的Debian/Ubuntu,使用

apt-get install python3-pip

安装pip3。


2013年的旧答案(easy_install现在已弃用):

使用setuptools安装pip: sudo easy_install pip

(我知道我上面的回答与klobucar的回答是多余的,但我还不能添加注释),所以这里有一个解决sudo的答案:easy_install:命令在Debian/Ubuntu上找不到:sudo apt-get install python-setuptools

同样,对于python3,使用easy_install3和python3-setuptools。

对于Python 3,使用apt-get install python3-pip。

安装Python的最新版本

它有很多下载链接,比如numpy和scipy

进入终端,输入如下命令:—

sudo easy_install pip

对于Python安装包,请检查此选项

Requirements for Installing Packages This section describes the steps to follow before installing other Python packages. Install pip, setuptools, and wheel If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but will need to upgrade to the latest version: On Linux or OS X: pip install -U pip setuptools On Windows: python -m pip install -U pip setuptools If you’re using a Python install on Linux that’s managed by the system package manager (e.g “yum”, “apt-get” etc…), and you want to use the system package manager to install or upgrade pip, then see Installing pip/setuptools/wheel with Linux Package Managers Otherwise: Securely Download get-pip.py 1 Run python get-pip.py. 2 This will install or upgrade pip. Additionally, it will install setuptools and wheel if they’re not installed already.

为什么不直接执行sudo easy_install pip,或者如果这是针对python 2.6的sudo easy_install-2.6 pip?

这将使用默认的python包安装系统安装pip,同时为您省去手动设置的麻烦。

这将允许您运行pip命令进行python包安装,因为它将与系统python一起安装。我还建议一旦有了pip,就使用virtualenv包和模式。:)

我花了很长时间浏览本页上的所有答案,但在s-walsh的OP问题的评论中找到了一个对我有用的答案

答案是使用pip3:

$ pip3 install <name-of-install>