Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named 'beautifulsoup4' in python3

$ virtualenv test
$ source test/bin/activate
$ pip3 install beautifulsoup4

Now the script test.py

import urllib.request
import sys
import unittest, time, re

import requests
from bs4 import BeautifulSoup

class Sel(unittest.TestCase):

    def setUp(self):
        self.base_url = "file:///Users/ishandutta2007/Desktop/cars/cars-price-list.html"

    def test_sel(self):
        with urllib.request.urlopen(self.base_url) as url:
            html_source = url.read()
        data = html_source#.encode('utf-8')
        parsed_html = BeautifulSoup(data, 'html.parser')

if __name__ == "__main__":
    unittest.main()

when I run $python3 test.py

File "test.py", line 6, in from bs4 import BeautifulSoup ModuleNotFoundError: No module named 'bs4'

then tried with

from beautifulsoup4 import BeautifulSoup

File "test.py", line 6, in from beautifulsoup4 import BeautifulSoup ModuleNotFoundError: No module named 'beautifulsoup4'

requirements clearly shows both

$ pip3 freeze > requirements.txt
$ cat requirements.txt 
beautifulsoup4==4.6.0
certifi==2018.1.18
chardet==3.0.4
idna==2.6
requests==2.18.4
urllib3==1.22
like image 221
ishandutta2007 Avatar asked Mar 08 '18 09:03

ishandutta2007


2 Answers

Only install BeautifulSoup4 instead of bs4 and BeautifulSoup then,

do this:

from bs4 import BeautifulSoup
like image 146
Abdullah Ahmed Ghaznavi Avatar answered Oct 22 '22 14:10

Abdullah Ahmed Ghaznavi


I would do this for a work around:

All of this under your created virtual environment

$ wget https://pypi.python.org/pypi/beautifulsoup4
$ pip3 install beautifulsoup4-4.6.0-py3-none-any.whl
$ pip3 freeze |grep beautifulsoup4
$ python3
>>> from bs4 import BeautifulSoup
like image 1
Joseph D. Avatar answered Oct 22 '22 13:10

Joseph D.