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

查看:1329
本文介绍了如何从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:\Python27\Lib\中有一个名为"ensurepip"的文件夹.

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

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

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

推荐答案

对于不熟悉Python的任何新手,小笔记:此处 所述.

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,首先请确保您已拥有Pip.因此,输入您的CMD:

To execute Pip, first of all make sure you have it. 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>

<command>是要运行的任何Pip命令,<args>是其相对参数,以空格分隔.

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天全站免登陆