如何从 CMD 运行 Pip 命令 [英] How to run Pip commands from CMD

查看:108
本文介绍了如何从 CMD 运行 Pip 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,Python 2.7.9 附带安装了 Pip,但是当我尝试从 CMD (Windows) 执行 Pip 命令时,我收到以下错误:

As I understand, Python 2.7.9 comes with Pip installed, however when I try to execute a Pip command from CMD (Windows) I get the following error:

'pip' is not recognized as an internal or external command, operable program or batch file.

当我输入 python 时,我得到以下信息,这表明它已正确安装:

When I type python I do get the following, which suggests it has been installed correctly:

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

然而,我确实需要添加一些环境变量才能让 python 部分在 CMD 上工作:

I did however need to add some environmental variables to get the python part working on CMD:

  • 添加环境变量PATH:"C:Python27"

定义系统变量PYTHONPATH:"C:Python27"

我在 Python 目录中找不到 Pip 文件夹,但是在 C:Python27Lib 中有一个名为ensurepip"的文件夹.

I cannot find a Pip folder within the Python directory, however there is a folder called "ensurepip" in C:Python27Lib.

有人知道如何让 Pip 命令开始在 CMD 中工作吗?

Does anybody know how can I get Pip commands to start working in CMD?

推荐答案

给没有自己解决的 Python 新手的小注:这在安装 Python 时应该是自动的,但为了以防万一,请注意在 Windows 的 CMD 中使用 python 命令运行 Python您必须首先将其添加到 PATH 环境变量中,如此处强>.

Little side note for anyone new to Python who didn't figure it out by theirself: this should be automatic when installing Python, but just in case, note that to run Python using the python command in Windows' CMD you must first add it to the PATH environment variable, as explained here.

要执行 Pip,首先要确保你已经安装了它,所以输入你的 CMD:

To execute Pip, first of all make sure you have it installed, so type in your CMD:

> python
>>> import pip
>>>

它应该不会出错.否则,如果此操作失败,您可以查看此处 看看如何安装它.现在你确定你已经有了 Pip,你可以使用 -m(模块)参数从 CMD 和 Python 运行它,像这样:

And it should proceed with no error. Otherwise, if this fails, you can look here to see how to install it. Now that you are sure you've got Pip, you can run it from CMD with Python using the -m (module) parameter, like this:

> python -m pip <command> <args>

其中 是您要运行的任何 Pip 命令, 是其相对参数,以空格分隔.

Where <command> is any Pip command you want to run, and <args> are its relative arguments, separated by spaces.

例如安装一个包:

> python -m pip install <package-name>

这篇关于如何从 CMD 运行 Pip 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆