Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当默认目录为python2.7时,如何将beautifulsoup安装到python3中?_Python_Python 3.x_Beautifulsoup_Pip - Fatal编程技术网

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

当默认目录为python2.7时,如何将beautifulsoup安装到python3中?,python,python-3.x,beautifulsoup,pip,Python,Python 3.x,Beautifulsoup,Pip,我已经安装了Python2.7和Python3.5。当我键入pip install beautifulsoup4时,它告诉我它已经安装在python2.7/site-package目录中 但是如何将其安装到python3目录中?我认为pip3将满足您的需要,请在终端上使用以下命令: pip3 install beautifulsoup4 请参见以root用户身份运行: apt-get install python3-bs4 #or pip3 install beautifulsoup4 然后

我已经安装了Python2.7和Python3.5。当我键入
pip install beautifulsoup4
时,它告诉我它已经安装在python2.7/site-package目录中


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

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

pip3 install beautifulsoup4
请参见以root用户身份运行:

apt-get install python3-bs4
#or
pip3 install beautifulsoup4
然后像这样导入它:

import bs4

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

python -m pip install bs4

如果您使用的是最新版本的Debian或Ubuntu Linux,则可以使用system package manager安装Beauty Soup:

$ apt-get install python-bs4 (for Python 2)
$ apt-get install python3-bs4 (for Python 3)
安装后导入库

from bs4 import BeautifulSoup

如果您在windows上,这也适用于Python3
py-m pip通过运行
pip3
来安装bs4

?您是否知道为什么它被安装为beautifulsoup4并称为bs4?没有,我不知道,但可能您不必编写
import beautifulsoup4作为bs4
当您尝试从模块访问类时,例如
bs4.PageElement