简体   繁体   中英

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

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

But how do I install it into the python3 dir?

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

pip3 install beautifulsoup4

See doc

Run as 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:

$ 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. I was installing this project Th3Jock3R/LinuxGSM-Arma3-Mod-Update to a linux centos8 dedicated Arma3 server. 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). 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. -Bob-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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