user9386864
user9386864

Reputation:

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

Upvotes: 1

Views: 27053

Answers (6)

Newton
Newton

Reputation: 31

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

Upvotes: 1

Ricardo
Ricardo

Reputation: 1

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

!conda install -c anaconda beautifulsoup4

In code:

from bs4 import BeautifulSoup

Upvotes: 0

Vin Bolisetti
Vin Bolisetti

Reputation: 45

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
    

Upvotes: 3

Alejandro Araujo
Alejandro Araujo

Reputation: 499

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

Upvotes: 2

user9386864
user9386864

Reputation:

This works from bs4 import BeautifulSoup enter image description here

Upvotes: 1

bastingup
bastingup

Reputation: 149

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!

Upvotes: 1

Related Questions