0

Sorry I know this question has come up a bit but I am stumped. Previously working fine code is now no longer working. I have tried uninstalling and reinstalling python 3.8.5, setting up new environments, stripping the code back to basics. I've installed and uninstalled BS4 and Beautifulsoup4 dozens of times.

My method is pip3 install bs4

The installation goes fine but when I run the code I get

File "/Users/rupertdenton/Desktop/Coding/Anybody/tester.py", line 1, in <module>
    from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'

I triple check python version and it is 3.8.5 and reinstall again with success:

Requirement already satisfied: soupsieve>1.2 in ./venv/lib/python3.8/site-packages (from beautifulsoup4->bs4) (2.0.1)
Installing collected packages: beautifulsoup4, bs4
Successfully installed beautifulsoup4-4.9.1 bs4-0.0.1

But still the code throws the same error. Here is the pared back code which worked fine until about a week ago.

from bs4 import BeautifulSoup

def scrapecafes(city, area):

    #url = 'https://www.broadsheet.com.au/melbourne/guides/best-cafes-thornbury' #go to the website
    url = f"https://www.broadsheet.com.au/{city}/guides/best-cafes-{area}"
    response = requests.get(url, timeout=5)

    soup_cafe_names = BeautifulSoup(response.content, "html.parser")
    type(soup_cafe_names)

    cafeNames = soup_cafe_names.findAll('h2', attrs={"class":"venue-title", }) #scrape the elements
    cafeNamesClean = [cafe.text.strip() for cafe in cafeNames]
deadant88
  • 920
  • 9
  • 24

1 Answers1

0

if your code is depending on the environment, you need to activate the environment first.

. env/bin/activate

if env is the name of your environment.

Then

pip3 install bs4 requests

Then run your program.

karlcow
  • 6,977
  • 4
  • 38
  • 72
  • Thanks for the response my env is called venv unfortunately still no love ``(venv) (base) ruperts-mbp:anybody [username]$`` – deadant88 Aug 19 '20 at 09:14