我正在尝试安装美丽的汤 https://en.wikipedia.org/wiki/Beautiful_Soup using pip
在 Python 2.7 中。我不断收到错误消息,但不明白为什么。
我按照说明安装了pip,它被安装到以下目录:c:\Python27\Scripts\pip.exe
。然后我尝试将其添加到路径中,并运行pip install package
命令。
我尝试了两种不同的方式:
import sys
sys.path.append('C:\\Python27\\Scripts\\pip.exe')
pip install beautifulsoup4
import sys
sys.path.append('C:\\Python27\\Scripts')
pip install beautifulsoup4
两者都给我这个错误消息:
>>> pip install beautifulsoup4
SyntaxError: invalid syntax
shell 突出显示“install”一词,并指出它的语法无效。
这是怎么回事?
pip
is a 命令行工具,不是 Python 语法。
换句话说,在控制台中运行命令,not在Python解释器中:
pip install beautifulsoup4
您可能必须使用完整路径:
C:\Python27\Scripts\pip install beautifulsoup4
or even
C:\Python27\Scripts\pip.exe install beautifulsoup4
然后 Windows 将执行pip
程序和that将使用Python来安装包。
另一种选择是使用 Python-m
命令行开关来运行pip
模块,其运行方式与pip
命令:
python -m pip install beautifulsoup4
or
python.exe -m pip install beautifulsoup4
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)