Python 如何在 Windows PowerShell 中使用 pip 安装包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30963446/
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 install packages with pip in Windows PowerShell
提问by David
I am using Python 2.7.9 on a Windows 8 computer.
我在 Windows 8 计算机上使用 Python 2.7.9。
I tried to install lxml by typing pip install lxml
in Windows PowerShell after typing python
, but I get the following error: SyntaxError: invalid syntax
我尝试在键入pip install lxml
后通过在 Windows PowerShell 中键入来安装 lxml python
,但出现以下错误:SyntaxError: invalid syntax
I tried installing pip by using the following tutorial http://www.tylerbutler.com/2012/05/how-to-install-python-pip-and-virtualenv-on-windows-with-powershell/only to later realize that I already had pip.exe, pip2.7.exe and pip2.exe installed when I first installed Python. They are located in the C:\Python27\Scripts directory.
我尝试使用以下教程安装 pip http://www.tylerbutler.com/2012/05/how-to-install-python-pip-and-virtualenv-on-windows-with-powershell/后来才意识到我第一次安装 Python 时已经安装了 pip.exe、pip2.7.exe 和 pip2.exe。它们位于 C:\Python27\Scripts 目录中。
Yet, if I try something like pip help
I will get an invalid syntax error.
然而,如果我尝试类似的操作,pip help
我会得到一个无效的语法错误。
Do I have to reinstall pip or how do I get it to work in order to install the lxml library.
我是否必须重新安装 pip 或者如何让它工作才能安装 lxml 库。
Thank you for any help you can provide.
感谢您提供任何帮助。
采纳答案by Christopher
I had the same problem. You need to set the PATH environment variable, so that the system recognizes the command "pip".
我有同样的问题。您需要设置PATH环境变量,以便系统识别命令“pip”。
If typing easy_install or pip [in PowerShell] doesn't work, it means the Scripts folder is not in your path. Run the next command in that case (Note that this command must be run only once or your PATH will get longer and longer). Make sure to replace c:\Python33\Scripts with the correct location of your Python installation:
如果在 PowerShell 中输入 easy_install 或 pip 不起作用,则意味着 Scripts 文件夹不在您的路径中。在这种情况下运行下一个命令(请注意,此命令只能运行一次,否则您的 PATH 会越来越长)。确保将 c:\Python33\Scripts 替换为 Python 安装的正确位置:
setx PATH "%PATH%;C:\Python33\Scripts"
Close and reopen PowerShell after running this command.
运行此命令后关闭并重新打开 PowerShell。
Source: http://arunrocks.com/guide-to-install-python-or-pip-on-windows/
来源:http: //arunrocks.com/guide-to-install-python-or-pip-on-windows/
回答by user3636636
Starting from Python versions 2.7.9 and 3.4.0, 'pip' is already included in the regular install. Check if the path to the 'Scripts' directory inside your Python installation directory is contained in your system's 'PATH' environment variable, so 'pip' can be found.
从 Python 版本 2.7.9 和 3.4.0 开始,'pip' 已经包含在常规安装中。检查 Python 安装目录中“Scripts”目录的路径是否包含在系统的“PATH”环境变量中,以便可以找到“pip”。
Look here for more information:
在这里查看更多信息:
How do I install pip on Windows?
Edit: Sounds like you are trying to run pip inside python, You shouldn't get an 'invalid syntax' error through the command prompt. More like "'pip' is not recognized". Try simply just opening command prompt and typing 'pip help'
编辑:听起来您正在尝试在 python 中运行 pip,您不应该通过命令提示符收到“无效语法”错误。更像是“无法识别‘pip’”。尝试简单地打开命令提示符并输入“pip help”