ImportError: No module named bs4 how fix - python

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

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

how to solve "ModuleNotFoundError: No module named 'beautifulsoup4'"?

I'm work in Python Idle.
I installed BeautifulSoup4 with "pip install beautifulsoup4" in Powershell, and it works in Powershell's python.
But when I run in Python Idle
# Read Library
from bs4 import BeautifulSoup
error message said
Traceback (most recent call last):
File "C:/Users/umts1202/Desktop/ML/bs-test1.py", line 2, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
I have no idea what to do. Please help me :(

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' >>>

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'>
>>>

import error due to bs4 vs BeautifulSoup

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.

Categories

Resources