'Jupiter notebook and BeautifulSoup4 installation

I have installed BeautifulSoup both using pip install beautifulsoup4pip install and using conda install -c anaconda beautifulsoup4 and also tried to install it directly from the jupiter notebook using

    import pip

    if int(pip.__version__.split('.')[0])>9:
        from pip._internal import main
    else:
        from pip import main
    def install(package):
        main(['install', package])

install('BeautifulSoup4')

When I try to import the module I get

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-8-9e5201d5ada7> in <module>
----> 1 import BeautifulSoup4

ModuleNotFoundError: No module named 'BeautifulSoup4'`

I want to premise that I'm a noob at this, I always have problems understanding where I should install new python modules, and for some reason they always get installed everywhere but where I need them. I searched here and on google but I could not find a answer that worked or that could set me on the right track to solve the problem.

Could some PRO explain step by step how to install the modules correctly, so that myself and the other people who might read this can, not only fix the problem, but also understand better how the problem was originated and how to fix similar problems in the future? Thanks

Screenshot of jupiter notebook



Solution 1:[1]

It depends on which platform you are using to build your Notebook:

  1. Cognitiveclass:
from bs4 import BeautifulSoup

 Does not work directly

  1. IBM Watson Studio
from bs4 import BeautifulSoup

 Work directly

Solution 2:[2]

Perform the following steps:

  1. Open a new anaconda prompt

  2. Run conda install -c anaconda beautifulsoup4

  3. Close and reopen jupyter notebook

  4. In jupyter notebook import libraries as following:

    from bs4 import BeautifulSoup
    

Solution 3:[3]

Please note, that I do not consider myself to be a pro, but I ran into this problem several times. The following helped me resolve it in every python project so far:

As far as I can tell from the information you have provided, everything worked out and the package should be installed correctly. Your script can't "find" it anywhere. The following should resolve it from my personal experience:

(1) You will need to add your python to environment variables in your system settings. A detailed description can be found over here: How to add to the pythonpath in Windows? (2) Append the path where you have installed your site packages to your project. If you could, append them all. By that I mean "site-packages" and "site-packages/beautifulsoup4" (or whatever the exact folder is):

import sys
sys.path.append(r"WhereverYourPackagesAre/site-packages") sys.path.append(r"WhereverYourPackagesAre/site-packages/beautifulsoup4")

The r before the string (your path you put in between the "") will convert the string to a raw-string. This has always resolved the issue for me. Hope this solves it!

Solution 4:[4]

This works from bs4 import BeautifulSoup enter image description here

Solution 5:[5]

It works, but you have to add the ! signal, like this:

!conda install -c anaconda beautifulsoup4

In code:

from bs4 import BeautifulSoup

Solution 6:[6]

What worked for me was just using !pip install beautifulsoup in the cell

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alejandro Araujo
Solution 2 RobC
Solution 3 bastingup
Solution 4
Solution 5 jizhihaoSAMA
Solution 6 Newton