I am working on a web scraping project, my first two lines of code are:
import requests
from bs4 import BeautifulSoup
Output in vscode:
p/Capstone/Web_scraper.py
Traceback (most recent call last):
File "/Users/nickruizmac/Desktop/Capstone/Web_scraper.py", line 2, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named ‘bs4’
Through terminal here are my current versions of pip and python
Python:
python3 –version = 3.11.4
Pip:
pip -V = pip 23.1.2 from /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip (python 3.11)
I am on the newer side when it comes to the Mac OS so I am not as well versed in it as I would be with Windows. I believe it may be an issue of install location. Any help would be greatly appreciated.
2
Answers
You need to install the
beautifulsoup4
package using thepip install beautifulsoup4
command.If you already have it installed, choose the correct interpreter for the Python extension (Ctrl+Shift+P –>
Python: Select Interpreter
).You can use the
pip show beautifulsoup4
command to view the installation information of thebeautifulsoup4
package, including the installation location.It’s definitely not your computer that is the problem. I am using a Mac as I am responding to this very post and also use BeautifulSoup on it. In my IDE (PyCharm) you are having to install the package beforehand and only then use the code
from bs4 import BeautifulSoup
. Usually you are having to "pip-install" it within your executer-terminal and thus achieve the same. To only writeimport BeautifulSoup
won’t do the trick.(BTW, I would try changing the title to Soup instead of Soap, might lead to confusion.)