skip to Main Content

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


  1. You need to install the beautifulsoup4 package using the pip install beautifulsoup4 command.

    If you already have it installed, choose the correct interpreter for the Python extension (Ctrl+Shift+P –> Python: Select Interpreter).

    enter image description here

    You can use the pip show beautifulsoup4 command to view the installation information of the beautifulsoup4 package, including the installation location.

    enter image description here

    Login or Signup to reply.
  2. 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 write import BeautifulSoup won’t do the trick.

    (BTW, I would try changing the title to Soup instead of Soap, might lead to confusion.)

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search