dakylesta
dakylesta

Reputation: 21

Why is BeautifulSoup not found?

I am on Mac OS and am trying to import beautiful soup. I keep getting this error. After spending hours on trying all sorts of things to figure it out I figure I'd ask you guys.

Please help! Thanks

from bs4 import BeautifulSoup

Traceback (most recent call last): File "/Users/kyle/Documents/Python Scripts/Count Cokes Sold 2.py", line 8, in from bs4 import BeautifulSoup ModuleNotFoundError: No module named 'bs4'

I have tried uninstalling and reinstalling both python and beautiful soup. I have also looked at my system to see where files are stored:

import sys
print(sys.path)

['/Users/kyle/Documents/Python Scripts', '/Users/kyle/Documents', '/Library/Frameworks/Python.framework/Versions/3.12/lib/python312.zip', '/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12', '/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages']

In the terminal window, here is where it says beautifulsoup4 is stored:

(base) kyle@Kyles-MacBook-Air ~ % pip install BeautifulSoup4
Collecting BeautifulSoup4
  Using cached beautifulsoup4-4.12.3-py3-none-any.whl.metadata (3.8 kB)
Requirement already satisfied: soupsieve>1.2 in /opt/anaconda3/lib/python3.11/site-packages (from BeautifulSoup4) (2.5)
Using cached beautifulsoup4-4.12.3-py3-none-any.whl (147 kB)
Installing collected packages: BeautifulSoup4
Successfully installed BeautifulSoup4-4.12.3

Upvotes: 1

Views: 352

Answers (3)

dakylesta
dakylesta

Reputation: 21

python3.12 -m pip install beautifulsoup4

My issue was that pip was installing beautifulsoup4 to python 3.11. I ran the code above in the Terminal to make pip install it to 3.12 and problem was solved.

Upvotes: 1

reidemption
reidemption

Reputation: 61

Are you using PythonKit? I have had a lot of problems with custom modules with embedded python versions. You can't just simply install them in pip (in my case at least). I had to go here and hope the library was available here (https://anaconda.org/beeware/repo).. if it is I installed it with pip install --prefer-binary --extra-index-url https://pypi.anaconda.org/beeware/simple --target <some folder> <pkgname>

Lmk if this is wrong in anyway :)

Upvotes: 0

John Gordon
John Gordon

Reputation: 33275

You have (at least) two different versions of Python installed on your computer. Did you do this on purpose?

pip is using Python 3.11:

/opt/anaconda3/lib/python3.11/site-packages

But you are using Python 3.12 to execute the code:

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages

The general answer in this situation is to pick which python version you want to use, and adjust your environment accordingly so that all your tools agree on that version.

Upvotes: 0

Related Questions