当默认目录为python2.7时,如何将beautifulsoup安装到python3中?

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

How to install beautifulsoup into python3, when default dir is python2.7?

pythonpython-3.xbeautifulsouppip

提问by ERJAN

I have both Python 2.7 and Python 3.5 installed. When I type pip install beautifulsoup4it tells me that it is already installed in python2.7/site-package directory.

我安装了 Python 2.7 和 Python 3.5。当我输入时,pip install beautifulsoup4它告诉我它已经安装在 python2.7/site-package 目录中。

But how do I install it into the python3 dir?

但是如何将它安装到 python3 目录中?

回答by Alan Francis

I think pip3 will satisfy your needs, use the below command on the terminal:

我认为 pip3 将满足您的需求,请在终端上使用以下命令:

pip3 install beautifulsoup4

See doc

文档

回答by Mehdi Nellen

Run as root:

以 root 身份运行:

apt-get install python3-bs4
#or
pip3 install beautifulsoup4

Afterwards import it like this:

然后像这样导入它:

import bs4

回答by Shvet Chakra

The package is bs4 and can be installed with following command:

该软件包是 bs4,可以使用以下命令安装:

python -m pip install bs4

回答by Hossain Misho

If you're using a recent version of Debian or Ubuntu Linux, you can install Beautiful Soup with the system package manager:

如果您使用的是最新版本的 Debian 或 Ubuntu Linux,您可以使用系统包管理器安装 Beautiful Soup:

$ apt-get install python-bs4 (for Python 2)
$ apt-get install python3-bs4 (for Python 3)

Afer install import the library

安装后导入库

from bs4 import BeautifulSoup