27

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
ERJAN
  • 23,696
  • 23
  • 72
  • 146

6 Answers6

70

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

pip3 install beautifulsoup4

See doc

Alan Francis
  • 1,249
  • 11
  • 17
15

Run as root:

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

Afterwards import it like this:

import bs4
Mehdi Nellen
  • 8,486
  • 4
  • 33
  • 48
  • Do you happen to know why it is installed as beautifulsoup4 and called as bs4? – Mischief_Monkey May 13 '20 at 05:50
  • 1
    @Mischief_Monkey No, I don't know but probably so you don't have to write `import beautifulsoup4 as bs4` it saves a lot of typing when you try to access classes from the module e.g. `bs4.PageElement` – Mehdi Nellen May 14 '20 at 14:51
7

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
Hossain Misho
  • 121
  • 1
  • 2
3

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

python -m pip install bs4
Shvet Chakra
  • 1,043
  • 10
  • 21
1

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. Then pointing directories in Th3Jock3R:s script A3_SERVER_FOLDER = "" and A3_SERVER_DIR = "/home/arma3server{}".format(A3_SERVER_FOLDER) placing and running the script in same folder /home/arma3server with python3 update.py. In this folder is also located new folder called 'modlists' Now the lightness of mod loading blows my mind. -Bob-

Peacebob
  • 11
  • 3
0

If you are on windows, this works for Python3 as well py -m pip install bs4

jubot
  • 1