Python 使用 pip 安装漂亮的汤

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

install beautiful soup using pip

pythonpython-2.7beautifulsouppip

提问by Big Russ

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

我正在尝试使用pipPython 2.7安装 BeautifulSoup 。我不断收到错误消息,不明白为什么。

I followed the instructions to install pip, which was installed to the following directory: c:\Python27\Scripts\pip.exe, then I tried adding it to the path, and running the pip install packagecommand.

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

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.

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

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

我不知道发生了什么,所以任何帮助将不胜感激。

采纳答案by Martijn Pieters

pipis a command line tool, not Python syntax.

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

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

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

pip install beautifulsoup4

You may have to use the full path:

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

C:\Python27\Scripts\pip install beautifulsoup4

or even

甚至

C:\Python27\Scripts\pip.exe install beautifulsoup4

Windows will then execute the pipprogram and thatwill use Python to install the package.

那么Windows将执行该pip计划,并认为将使用Python来安装软件包。

Another option is to use the Python -mcommand-line switch to run the pipmodule, which then operates exactly like the pipcommand:

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

python -m pip install beautifulsoup4

or

或者

python.exe -m pip install beautifulsoup4

回答by Daniel Adenew

The easy method that will work even in corrupted setup environment is :

即使在损坏的安装环境中也能使用的简单方法是:

To download ez_setup.py and run it using command line

下载ez_setup.py并使用命令行运行它

python ez_setup.py

蟒蛇ez_setup.py

output

输出

Extracting in c:\uu\uu\appdata\local\temp\tmpjxvil3 Now working in c:\u\u\appdata\local\temp\tmpjxvil3\setuptools-5.6 Installing Setuptools

Extracting in c:\uu\uu\appdata\local\temp\tmpjxvil3 Now working in c:\u\u\appdata\local\temp\tmpjxvil3\setuptools-5.6 Installing Setuptools

run

pip install beautifulsoup4

pip 安装 beautifulsoup4

output

输出

Downloading/unpacking beautifulsoup4 Running setup.py ... egg_info for package Installing collected packages: beautifulsoup4 Running setup.py install for beautifulsoup4 Successfully installed beautifulsoup4 Cleaning up...

Downloading/unpacking beautifulsoup4 Running setup.py ... egg_info for package Installing collected packages: beautifulsoup4 Running setup.py install for beautifulsoup4 Successfully installed beautifulsoup4 Cleaning up...

Bam ! |Done?

砰!|完成了吗?

回答by xahiru

If you have more than one version of python installed, run the respective pipcommand.

如果您安装了多个版本的 python,请运行相应的 pip命令。

For example for python3.6 run the following

例如对于 python3.6 运行以下

pip3.6 install beautifulsoup4

To check the available command/version of pipand pythonon Macrun

要在Mac上检查pippython的可用命令/版本,请运行

ls /usr/local/bin

回答by JON

import os

os.system("pip install beautifulsoup4")

or

import subprocess

exe = subprocess.Popen("pip install beautifulsoup4")

exe_out = exe.communicate()

print(exe_out)