使用 pip 安装漂亮的汤 [英] install beautiful soup using pip

查看:34
本文介绍了使用 pip 安装漂亮的汤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Python 2.7 中使用 pip 安装 BeautifulSoup.我不断收到错误消息,但不明白为什么.

我按照说明安装了pip,它安装到以下目录:c:Python27Scriptspip.exe,然后我尝试将其添加到路径中,并运行pip install package 命令.

尝试了两种不同的方式:

导入系统sys.path.append('C:\Python27\Scripts\pip.exe')pip 安装 beautifulsoup4导入系统sys.path.append('C:\Python27\Scripts')pip 安装 beautifulsoup4

两者都给我这个错误信息:

<预><代码>>>>pip 安装 beautifulsoup4语法错误:无效语法

shell 突出显示了安装"这个词,并说它是无效的语法.

我不知道发生了什么,因此非常感谢您的帮助.

解决方案

pip 是一个命令行工具,而不是 Python 语法.

换句话说,在你的控制台中运行命令,不是在 Python 解释器中:

pip install beautifulsoup4

您可能必须使用完整路径:

C:Python27Scriptspip install beautifulsoup4

甚至

C:Python27Scriptspip.exe 安装 beautifulsoup4

Windows 将执行 pip 程序,那个将使用 Python 安装包.

另一种选择是使用 Python -m 命令行开关来运行 pip 模块,然后它的操作与 pip 完全一样命令:

python -m pip install beautifulsoup4

python.exe -m pip install beautifulsoup4

I am trying to install BeautifulSoup using pip in Python 2.7. I keep getting an error message, and can't understand why.

I followed the instructions to install pip, which was installed to the following directory: c:Python27Scriptspip.exe, then I tried adding it to the path, and running the pip install package command.

tried it two different ways:

import sys
sys.path.append('C:\Python27\Scripts\pip.exe')
pip install beautifulsoup4

import sys
sys.path.append('C:\Python27\Scripts')
pip install beautifulsoup4

both give me this error message:

>>> pip install beautifulsoup4
SyntaxError: invalid syntax

the shell is highlighting the word "install" and saying that it's invalid syntax.

I have no idea what's going on, so any help would be greatly appreciated.

解决方案

pip is a command line tool, not Python syntax.

In other words, run the command in your console, not in the Python interpreter:

pip install beautifulsoup4

You may have to use the full path:

C:Python27Scriptspip install beautifulsoup4

or even

C:Python27Scriptspip.exe install beautifulsoup4

Windows will then execute the pip program and that will use Python to install the package.

Another option is to use the Python -m command-line switch to run the pip module, which then operates exactly like the pip command:

python -m pip install beautifulsoup4

or

python.exe -m pip install beautifulsoup4

这篇关于使用 pip 安装漂亮的汤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆