import error due to bs4 vs BeautifulSoup - python

I am trying to use beautifulsoup compatible lxml and it is giving me an error:
from lxml.html.soupparser import fromstring
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/lxml/html/soupparser.py", line 7, in <module>
from BeautifulSoup import \
ImportError: No module named BeautifulSoup
I have bs4 installed. How do I fix this issue?

The error is caused by soupparser.py trying to import BeautifulSoup version 3 while you have version 4 installed. The module name was changed from BeautifulSoup to bs4 in version 4.
You can trick soupparser.py into importing version 4 by mapping the bs4 module to BeautifulSoup in sys.modules before importing soupparser:
import sys, bs4
sys.modules['BeautifulSoup'] = bs4
from lxml.html.soupparser import fromstring

There is now a version of soupparser that works with bs4. It's available here: https://github.com/lxml/lxml/blob/master/src/lxml/html/soupparser.py

Try adding :
from bs4 import BeautifulSoup
and make sure you have the correct version of BeautifulSoup for your system installed.

Related

BS4 module not found

Traceback (most recent call last):
File "d:/project.py", line 2, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
Guys any idea why i get this error.
Ive installed bs4 with cmd and pip
Where do i have to install the module i am really confused
Some of them work and some of them dont
For example, bs4 doesnt but tkinter does

ModuleNotFoundError: No module named 'bs4' even after installing and re-installing

I'm trying to run my Python file. (py name.py)
from bs4 import BeautifulSoup as BS
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\bs4\__init__.py", line 29, in <module>
from .builder import builder_registry
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\bs4\builder\__init__.py", line 294, in <module>
from . import _htmlparser
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\bs4\builder\_htmlparser.py", line 7, in <module>
from html.parser import (
ImportError: cannot import name 'HTMLParseError' from 'html.parser' (C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\html\parser.py)
I installed this library using "pip".
After the library is completely removed and installed again, this error appears when you run this code.
File "name.py", line 9, in <module>
from bs4 import BeautifulSoup as BS
ModuleNotFoundError: No module named 'bs4'
I solved the problem. First I deleted all BS4 mentions from my PC. Then in CMD moved on path:
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts.
And spent there the command:
pip install beautifulsoup4

error when scraping the google search result and prints it

I'm using Python 3.6 and BeautifulSoup is installed in my computer with:
pip install beautifulsoup
How can I treat this:
Traceback (most recent call last): File "I:\application
python\rechere1.py", line 5, in from bs4 import
BeautifulSoup File "I:\application python\bs4.py", line 3, in
from bs4 import BeautifulSoup ImportError: cannot import
name 'BeautifulSoup' >>>

ImportError: No module named bs4 how fix

I have next python 2.7 (debian) code
import sys
import random
from bs4 import BeautifulSoup
from YandexDiskException import YandexDiskException
from YandexDiskRestClient import YandexDiskRestClient
I try run, but get this message
root#vps-1074211:/tmp/beautifulsoup4-4.4.0# python /var/vah13/untitled/grep.py
Traceback (most recent call last):
File "/var/vah13/untitled/grep.py", line 5, in <module>
from bs4 import BeautifulSoup
ImportError: No module named bs4
how fix it?
I installed
pip install beautifulsoup4
apt-get install python-bs4

Python can't find installed modules

I've used these modules before, even in a Python script inside a folder where I have other working scripts. Here's my imports:
import os
import sys
import urllib.request as urllib, simplejson as json, requests
import subprocess
import Popen, PIPE
import time
I get this in my console:
Traceback (most recent call last):
File "party.py", line 4, in <module>
import urllib.request as urllib, simplejson as json, requests
ImportError: No module named request
How come? I've tried
sudo pip install request
..but with no luck. What is causing this?
what python version are you using? urllib.request seems to be python3
v2.7
>>> import urllib.request
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named request
>>>
v3.3
>>> import urllib.request
>>> urllib.request
<module 'urllib.request' from '/usr/lib/python3.3/urllib/request.py'>
>>>

Categories

Resources