I was trying to run a simple python file using BeautifulSoup when I received the following error message in Atom.
ModuleNotFoundError: No module named 'bs4'
I have already installed BeautifulSoup using the following command in my Macbook's terminal.
$ pip3 install beautifulsoup4
I want to note that I have both Python 2.7.10 and Python 3.8.5 installed. I looked at my installed modules, and I only see 'bs4' in the modules for python3 and not in python.
When I try to place scrape.py in Atom or PyCharm, both text editors say that the module does not exist. Any help would be much appreciated, thank you.
scrape.py
import requests
from bs4 import BeautifulSoup
Traceback
Traceback (most recent call last):
File "/Users/lyons/Documents/scrape/scrape.py", line 2, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
[Finished in 2.237s]
If anyone runs into this - bs4 behaves unexpectedly when working with subprocess (my setup includes venv). What worked for me was a revision of the suggested solution:
def install_bs4():
subprocess.check_call([sys.executable, "-m", "pip", "install", "bs4"])
try:
from bs4 import BeautifulSoup
except:
install_bs4()
from bs4 import BeautifulSoup
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With