html5lib installed but BeautifulSoup cannot find it - python

I have installed the html5lib package. I'm sure because when i try to install it, i get a message that it is already installed.
pip install html5lib
Requirement already satisfied: html5lib in ./anaconda/lib/python3.5/site-packages
Also i am able to successfully import that package.
import html5lib
Yet when I try to use the parser as a part of the BeautifulSoup constructor
soup = BeautifulSoup(response.data, 'html5lib')
I'm unsuccessful
FeatureNotFound: Couldn't find a tree builder with the features you requested: html5lib. Do you need to install a parser library?
Is it possible to force bs4 to lookup the installed parsers and successfully find html5lib?

Took Megalng's suggestion and restarted the IDE. That did the trick!

Related

Python, get rid of BS4?

If we go to: https://pypi.org/project/bs4/ we can read:
This is a dummy package managed by the developer of Beautiful Soup to prevent name squatting. The official name of PyPI’s Beautiful Soup Python package is beautifulsoup4. This package ensures that if you type pip install bs4 by mistake you will end up with Beautiful Soup.
So given the following line in python: from bs4 import BeautifulSoup, Comment How can I replace it with beautifulsoup4? ie I don't want to install bs4 package at all as it's just a dummy package as claimed...
A distribution package and the import package it contains do not necessarily have the same name. In other words the thing that you install does not necessarily have the same name as the thing you import. Even though the convention is to give them the same name, there are exceptions. And "Beautiful Soup" is such an exception.
So you pip install beautifulsoup4 but you import bs4.
With that said, you can probably safely uninstall bs4:
python -m pip uninstall bs4
as long as you still have beautifulsoup4 installed:
python -m pip install beautifulsoup4
python -m pip show beautifulsoup4

BeautifulSoup not working in google colab

I have tried the below code in google colab but it gives an error which i have also shown below
!pip install beautifulsoup4
Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.7/dist-packages (4.6.3)
from beautifulsoup4 import BeautifulSoup
ModuleNotFoundError Traceback (most recent call last) in ()
----> 1 from beautifulsoup4 import BeautifulSoup
ModuleNotFoundError: No module named 'beautifulsoup4'
--------------------------------------------------------------------------- NOTE: If your import is failing due to a missing package, you can manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the "Open Examples" button below.
Than i also tried
!apt install BeautifulSoup4
E: Unable to locate package BeautifulSoup4
!apt install BeautifulSoup
E: Unable to locate package BeautifulSoup
I have also tried the above commands without exclamation mark (!). other packages were installed but beautifulsoup4 is not installing neither it is allowing to import.
I appreciate if someone can guide me regarding this.
for importing BeautifulSoup use that one:
from bs4 import BeautifulSoup
there's usual case a different package naming while installing and the step of importing/using
Instead of
from beautifulsoup4 import BeautifulSoup
Try out
from bs4 import BeautifulSoup
! pip install bs4
It worked very well in Google colaboratory.

ImportError: No module named bs4 - despite bs4 and BeautifulSoup being installed

I downloaded Python 3.7 and am running a script with "from bs4 import BeautifulSoup" and am receiving the following error on execution;
"File "myscript.py", line 3, in
from bs4 import BeautifulSoup ImportError: No module named bs4"
When I type "pip3 install bs4" or "pip3 install BeautifulSoup4" in the terminal I get the following;
"Requirement already satisfied: bs4 in
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
(0.0.1) Requirement already satisfied: beautifulsoup4 in
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
(from bs4) (4.6.3)"
Executing "import bs4" and "from bs4 import BeautifulSoup" in IDLE don't error out.
Any idea about what's going on?
Just pip install bs4.
Probably, you are maintaining different versions of Python.
check if you have more than one version of python, if so add the path of python 3.7 in the system setting and try removing the older python if possible
and then pip install BeautifulSoup
I had a similar problem with importing bs4. There is a similar question with many answers. I tried many things and nothing worked but when I installed poetry [https://python-poetry.org/ ]
$ poetry add pendulum
It sorted dependencies for me so I was able to import bs4.

Beautiful Soup not working in Pycharm

I am trying to import beautiful soup in my script, but get a module not found error.
Error Message
But the problem is that when i try to install it, i get the message below:
Ajays-MacBook-Pro:/ aj$ pip install bs4
Requirement already satisfied: bs4 in /anaconda/lib/python2.7/site-packages
Requirement already satisfied: beautifulsoup4 in /anaconda/lib/python2.7/site-packages (from bs4)
What am I doing wrong here?
Note: I tried importing bs4 in Jupyter notebook and it works without any issues.
You use different version of Python in the PyCharm, you should add the Python in the /anaconda folder in the PyCharm settings.
You just need to install BeautifulSoup4 from the terminal in pycharm.
Then when you try to import it in your code you need to change this statement
from BeautifulSoup import BeautifulSoup
to this
from bs4 import BeautifulSoup
That error will be solved.

Where is BeautifulSoup4 hiding?

I did sudo pip install BeautifulSoup4 and got an awfully optimistic response:
Downloading/unpacking beautifulsoup4
Running setup.py egg_info for package beautifulsoup4
Installing collected packages: beautifulsoup4
Running setup.py install for beautifulsoup4
Successfully installed beautifulsoup4
Cleaning up..
but when I try to use import BeautifulSoup4 or from BeautifulSoup4 import BeautifulSoup4 in a script, python says there's no module by that name.
> import BeautifulSoup
ImportError: No module named BeautifulSoup
Update: pip tells me beautifulsoup4 in /usr/local/lib/python2.6/dist-packages but I'm running 2.7.2+ (and print sys.path sees 2.7 paths) ... so now I need to figure out why pip is putting things in the wrong place.
Try import bs4. It's unfortunate there's no correspondence between PyPI package name and import name. After that the class names are the same as before eg. soup = bs4.BeautifulSoup(doc) will work.
If that still doesn't work, try pip install again and note the path to the package install. Then in your python console run import sys and print sys.path to make sure that the path is there.
You might need to explicitly specify pip-2.7 or switch to easy_install (or easy_install-2.7)
Try this:
from bs4 import BeautifulSoup
I had this issue while using VS Code and the Pylance extension. I was able to resolve it by finding the location of my python packages (in my case it was "c:\python39\lib\site-packages"), and adding that to the external resolution paths in Pylance's settings. Pylance was then able to locate the import. I used below code segment to import BeautifulSoup from bs4.
from bs4 import BeautifulSoup
After trying the easy_install and pip if things dont work then download the tz package from the package website untar it in a folder. Now open cmd window and go to the directory where you unzip the tz and run the command 'python setup.py install' IT should work

Categories