Python 新手:pip 安装和语法问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24272532/
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
Python newbie: pip install and syntax problems
提问by penGuinKeeper
New to Python here. I am running Python 2.7.7 x86 and Windows 7. I am trying to install the requests
module. I've tried:
这里是 Python 的新手。我正在运行 Python 2.7.7 x86 和 Windows 7。我正在尝试安装该requests
模块。我试过了:
pip install requests
in the Python shell and in the Windows command line (cmd) (I saw this question, which suggested using cmd), and I keep getting the same error:
在 Python shell 和 Windows 命令行 (cmd) 中(我看到了这个问题,建议使用 cmd),并且我不断收到相同的错误:
SyntaxError: invalid syntax
I tried to check if pip even installed correctly by running:
我试图通过运行来检查 pip 是否安装正确:
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])
print installed_packages_list
Which I got from this question. I got []
as the output. I'm interpreting this to mean that pip wasn't successfully installed. I tried reinstalling pip
by running get-pip.py
, and got the output:
我从这个问题中得到的。我得到了[]
作为输出。我将此解释为 pip 未成功安装。我尝试pip
通过运行重新安装get-pip.py
,并得到输出:
Requirement already up-to-date: pip in c:\python27\lib\site-packages
Cleaning up...
Which I'm interpreting as Python telling me pip was installed. I'm really confused now... how do I make sure pip is correctly installed, and then install the requests module? Any help would be appreciated.
我将其解释为 Python 告诉我 pip 已安装。我现在真的很困惑......我如何确保正确安装了pip,然后安装请求模块?任何帮助,将不胜感激。
采纳答案by Adam Smith
This is a commonly asked question, and one for which there's hardly a canonical answer that would be on-topic for SO (honestly this is more a Superuser thing, but since it's pertinent to coding -- even though it's NOT coding by any means -- it will fly here).
这是一个常见问题,并且几乎没有一个规范的答案可以成为 SO 的主题(老实说,这更像是一个超级用户的事情,但因为它与编码有关 - 即使它不是以任何方式编码 - - 它会飞到这里)。
If you have pip (by running get-pip.py
or etc) it will exist in your Python directory. If you're running Python 2.7, let's assume that that directory lives at C:\Python27\
. In which case, pip exists at C:\Python27\scripts\pip.exe
.
如果您有 pip(通过运行get-pip.py
等),它将存在于您的 Python 目录中。如果您运行的是 Python 2.7,我们假设该目录位于C:\Python27\
. 在这种情况下,pip 存在于C:\Python27\scripts\pip.exe
。
You can add that to your %PATH%
, or navigate there each time you want to use pip. Whatever is most convenient. If nothing else:
您可以将其添加到您的%PATH%
,或者每次要使用 pip 时导航到那里。什么最方便。如果没有别的:
COMMAND PROMPT WINDOW:
C:\users\yourname>set PATH = %PATH%;C:\python27\scripts
C:\users\yourname>pip install requests