简体   繁体   English

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

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

I have both Python 2.7 and Python 3.5 installed.我安装了 Python 2.7 和 Python 3.5。 When I type pip install beautifulsoup4 it tells me that it is already installed in python2.7/site-package directory.当我输入pip install beautifulsoup4它告诉我它已经安装在 python2.7/site-package 目录中。

But how do I install it into the python3 dir?但是如何将它安装到 python3 目录中?

I think pip3 will satisfy your needs, use the below command on the terminal:我认为 pip3 将满足您的需求,请在终端上使用以下命令:

pip3 install beautifulsoup4

See doc文档

Run as root:以 root 身份运行:

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

Afterwards import it like this:然后像这样导入它:

import bs4

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

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

python -m pip install bs4

如果您在 Windows 上,这也适用于 Python3 py -m pip install bs4

I had some mismatch between Python version and Beautifulsoup.我在 Python 版本和 Beautifulsoup 之间有些不匹配。 I was installing this project Th3Jock3R/LinuxGSM-Arma3-Mod-Update to a linux centos8 dedicated Arma3 server.我正在将此项目Th3Jock3R/LinuxGSM-Arma3-Mod-Update安装到 linux centos8 专用 Arma3 服务器。 Python3 and Beautifulsoup4 seem to match.So I updated Python3, removed manually Beautifulsoup files and re-installed it with: sudo yum install python3-beautifulsoup4 (note the number 3). Python3 和 Beautifulsoup4 似乎匹配。所以我更新了 Python3,手动删除了 Beautifulsoup 文件并重新安装: sudo yum install python3-beautifulsoup4 (注意数字 3)。 Works.作品。 With just pointing directories in Th3Jock3R:s script A3_SERVER_FOLDER = "" and A3_SERVER_DIR = "/home/arma3server/serverfiles/{}".format(A3_SERVER_FOLDER) and running the script in same folder by python3 update.py Now the lightness of mod loading blows my mind.只需在 Th3Jock3R:s 脚本 A3_SERVER_FOLDER = "" 和 A3_SERVER_DIR = "/home/arma3server/serverfiles/{}".format(A3_SERVER_FOLDER) 中指向目录并通过python3 update.py在同一文件夹中运行脚本现在 mod 加载的轻量级让我大吃一惊。 -Bob- -鲍勃-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM