如何在 Windows 的 python 上运行 pip?

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

How do I run pip on python for windows?

pythonpython-3.x

提问by quant

I've just installed python 3.5, ran Python 3.5 (32-bit)and typed

我刚刚安装了 python 3.5,运行Python 3.5 (32-bit)并输入

pip

and received the message:

并收到消息:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    pip
NameError: name 'pip' is not defined

I don't see any scripts directories in my path, but I found pip.pyin C:\Users\UserName\AppData\Local\Programs\Python\Python35-32\Scripts.

我在我的路径中没有看到任何脚本目录,但我pip.pyC:\Users\UserName\AppData\Local\Programs\Python\Python35-32\Scripts.

I selected the option to "Add python to environment variables" during installation, but it doesn't seem to have done anything.

我在安装过程中选择了“将 python 添加到环境变量”选项,但它似乎没有做任何事情。

I googled this and got this guide, which says that earlier versions need to add some path names. I don't have a C:\Python...directory so I tried adding the Scriptsfolder from above, same result.

我用谷歌搜索了这个并得到了这个指南,它说早期版本需要添加一些路径名。我没有C:\Python...目录,所以我尝试Scripts从上面添加文件夹,结果相同。

How do I install python so that it actually works (ie. I can run pip, install modules, etc.)?

如何安装 python 以使其实际工作(即,我可以运行 pip、安装模块等)?

回答by Eli Dinkelspiel

I have a Mac, but luckily this should work the same way:

我有一台 Mac,但幸运的是这应该以相同的方式工作:

pipis a command-line thing. You don't run it in python.

pip是命令行的东西。你不在 python 中运行它。

For example, on my Mac, I just say:

例如,在我的 Mac 上,我只是说:

$pip install somelib

$pip install somelib

pretty easy!

挺容易!

回答by Kevin Guan

Maybe you'd like try run pipin Python shell like this:

也许你想像这样尝试pip在 Python shell 中运行:

>>> import pip
>>> pip.main(['install', 'requests'])

This will install requestspackage using pip.

这将requests使用pip.



Because pipis a module in standard library, but it isn't a built-in function(or module), so you need import it.

因为pip是标准库中的一个模块,但它不是一个内置函数(或模块),所以你需要导入它。

Other way, you should run pipin system shell(cmd. If pipis in path).

其他方式,您应该pip在系统外壳程序中运行(cmd。如果pip在路径中)。

回答by Suyog Rajbhandari

First go to the pip documentation if not install before: http://pip.readthedocs.org/en/stable/installing/

如果之前没有安装,请先转到 pip 文档:http: //pip.readthedocs.org/en/stable/installing/

and follow the install pip which is first download get-pip.py from https://bootstrap.pypa.io/get-pip.py

并按照安装 pip 首先从https://bootstrap.pypa.io/get-pip.py下载 get-pip.py

Then run the following (which may require administrator access): python get-pip.py

然后运行以下命令(可能需要管理员访问权限):python get-pip.py