Python 如何从 CMD 运行 Pip 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29817447/
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
How to run Pip commands from CMD
提问by algorhythm
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:
据我了解,Python 2.7.9 安装了 Pip,但是当我尝试从 CMD (Windows) 执行 Pip 命令时,出现以下错误:
'pip' is not recognized as an internal or external command, operable program or batch file.
When I type python
I do get the following, which suggests it has been installed correctly:
当我输入时,python
我确实得到以下信息,这表明它已正确安装:
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.
I did however need to add some environmental variables to get the python part working on CMD:
然而,我确实需要添加一些环境变量才能让 python 部分在 CMD 上工作:
Add to the environment variable
PATH
:"C:\Python27\"
Define the system variable
PYTHONPATH
:"C:\Python27\"
添加到环境变量
PATH
:"C:\Python27\"
定义系统变量
PYTHONPATH
:"C:\Python27\"
I cannot find a Pip folder within the Python directory, however there is a folder called "ensurepip" in C:\Python27\Lib\
.
我在 Python 目录中找不到 Pip 文件夹,但是在C:\Python27\Lib\
.
Does anybody know how can I get Pip commands to start working in CMD?
有人知道如何让 Pip 命令开始在 CMD 中工作吗?
采纳答案by Marco Bonelli
Little side note for anyone new to Python who didn't figure it out by theirself: this should be automaticwhen 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.
对于没有自己弄清楚的 Python 新手来说,这应该是自动的,但为了以防万一,请注意,要使用python
Windows 的 CMD 中的命令运行 Python ,您必须首先将其添加到PATH
环境变量,如解释here。
To execute Pip, first of all make sure you have it. So type in your CMD:
要执行 Pip,首先要确保你拥有它。所以输入你的CMD:
> python
>>> import pip
>>>
And it should proceed with no error. Otherwise, if this fails, you can look hereto 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:
它应该没有错误地继续。否则,如果此操作失败,您可以在此处查看如何安装它。现在您确定您已经获得了 Pip,您可以使用-m
(module) 参数从 CMD 使用 Python 运行它,如下所示:
> python -m pip <command> <args>
Where <command>
is any Pip command you want to run, and <args>
are its relative arguments, separated by spaces.
<command>
你想运行的任何 Pip 命令在哪里,以及<args>
它的相对参数,用空格分隔。
For example, to install a package:
例如,要安装一个包:
> python -m pip install <package-name>
回答by Tamerz
Make sure to also add "C:\Python27\Scripts" to your path. pip.exe should be in that folder. Then you can just run:
确保还将“C:\Python27\Scripts”添加到您的路径中。pip.exe 应该在该文件夹中。然后你可以运行:
C:\> pip install modulename
回答by Arun Naudiyal
Go to the folder where Python is installed .. and go to Scripts folder .
转到安装 Python 的文件夹 .. 并转到 Scripts 文件夹。
Do all this in CMD and then type :
在 CMD 中执行所有这些操作,然后键入:
pip
pip
to check whether its there or not .
检查它是否存在。
As soon as it shows some list it means that it is there .
只要它显示一些列表,就意味着它就在那里。
Then type
然后输入
pip install <package name you want to install>
回答by Maddu Swaroop
Firstly make sure that you have installed python 2.7 or higher
首先确保你已经安装了 python 2.7 或更高版本
Open Command Prompt as administrator and change directory to python and then change directory to Scripts by typing cd Scripts then type pip.exe and now you can install modules Step by Step:
以管理员身份打开命令提示符并将目录更改为 python,然后通过键入 cd Scripts 将目录更改为 Scripts,然后键入 pip.exe,现在您可以逐步安装模块:
Open Cmd
type in "cd \" and then enter
type in "cd python2.7" and then enter
打开命令
输入“cd \”,然后输入
输入“cd python2.7”然后输入
Note that my python version is 2.7 so my directory is that so use your python folder here...
请注意,我的 python 版本是 2.7,所以我的目录是这样的,所以在这里使用你的 python 文件夹......
type in "cd Scripts" and enter
Now enter this "pip.exe"
Now it prompts you to install modules
输入“cd Scripts”并输入
现在输入这个“pip.exe”
现在它会提示你安装模块
回答by vamsi sai kommuri
Simple solution that worked for me is, set the path of python in environment variables,it is done as follows
对我有用的简单解决方案是,在环境变量中设置python的路径,如下完成
- Go to My Computer
- Open properties
- Open Advanced Settings
- Open Environment Variables
- Select path
- Edit it
- 转到我的电脑
- 打开属性
- 打开高级设置
- 开放环境变量
- 选择路径
- 编辑它
In the edit option click add and add following two paths to it one by one:
在编辑选项中单击添加并一一添加以下两个路径:
C:\Python27
C:\Python27\Scripts
and now close cmd and run it as administrator, by that pip will start working.
现在关闭 cmd 并以管理员身份运行它,然后 pip 将开始工作。
回答by Benoit Blanchon
Newer versions of Python come with py
, the Python Launcher, which is always in the PATH
.
较新版本的 Python 附带py
了Python Launcher,它始终位于PATH
.
Here is how to invoke pip
via py
:
以下是调用pip
via 的方法py
:
py -m pip install <packagename>
py
allows having several versions of Python on the same machine.
py
允许在同一台机器上有多个版本的 Python。
As an example, here is how to invoke the pip
from Python 2.7:
例如,以下是如何pip
从 Python 2.7调用:
py -2.7 -m pip install <packagename>
回答by Ziggler
In my case I was trying to install Flask. I wanted to run pip install Flaskcommand. But when I open command prompt it I goes to C:\Users[user]>. If you give here it will say pip is not recognized. I did below steps
就我而言,我试图安装 Flask。我想运行pip install Flask命令。但是当我打开命令提示符时,我会转到 C:\Users[user]>。如果你在这里给出,它会说 pip 不被识别。我做了以下步骤
On your desktop right click Computer and select Properties
在您的桌面上右键单击计算机并选择属性
Select Advanced Systems Settings
选择高级系统设置
In popup which you see select Advanced tab and then click Environment Variables
在您看到的弹出窗口中,选择“高级”选项卡,然后单击“环境变量”
In popup double click PATH and from popup copy variable value for variable name PATH and paste the variable value in notepad or so and look for an entry for Python.
在弹出窗口中双击 PATH 并从弹出窗口中复制变量名称 PATH 的变量值并将变量值粘贴到记事本左右,然后查找 Python 条目。
In my case it was C:\Users\[user]\AppData\Local\Programs\Python\Python36-32
就我而言,它是C:\Users\[user]\AppData\Local\Programs\Python\Python36-32
Now in my command prompt i moved to above location and gave pip install Flask
现在在我的命令提示符中,我移到了上面的位置并给了 pip install Flask