0

I'm trying to get BeautifulSoup4 set up so that I can run the following:

from bs4 import BeautifulSoup

However, when I go to install BeautifulSoup4, I get the following:

Defaulting to user installation because normal site-packages is not writeable. 
Requirement already satisfied: beautifulsoup4 in ./Library/Python/2.7/lib/python/site-packages (4.8.2)
Requirement already satisfied: soupsieve>=1.2 in ./Library/Python/2.7/lib/python/site-packages (from beautifulsoup4) (1.9.5)
Requirement already satisfied: backports.functools-lru-cache; python_version < "3" in ./Library/Python/2.7/lib/python/site-packages (from soupsieve>=1.2->beautifulsoup4) (1.6.1)

$ from bs4 import BeautifulSoup4
from: can't read /var/mail/bs4

When running in Python3 I get this error

Python 3.8.2 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import beautifulsoup4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'beautifulsoup4' from 'bs4' (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/bs4/__init__.py)

I have both Python 3 and Python 2.7 on my computer, but can't figure out how to get it to recognize bs4

Appreciate the advice!

justwow231
  • 13
  • 1

1 Answers1

0

Having multiple versions of Python on a system can lead to confusion, and it's a problem every python developer encounters at some point.

To address your question, try installing bs4 using the python -m command, for example python -m pip install beautifulsoup4. This ensures that pip will install the package to the python you called.

It also sounds like it is time to learn about virtual environments. Virtual environments allow you to seperate instances of python for each of your projects, so you don't get conflicts between packages.

If you would like more information on installing BeautifulSoup4 with multiple versions of python check out this question.

Rusty Robot
  • 1,725
  • 2
  • 13
  • 29