简体   繁体   中英

For Python3, installing beautifulsoup4, on MacOS, unable to import within code?

I'm having trouble with installation of (or is it usage of?!) the beautifulsoup4 package, with Python 3.6, on MacOS High Sierra (10.3). I experienced the problem first in PyCharm and then also had same issue from the MacOS terminal, as demonstrated below. I've searched high and low on Stackoverflow and on the web at large, but cannot find a post/explaination that seems to meet the very specific symptoms I'm experiencing.

First three lines of my Python 3 code file called “main.py”….

import numpy as np
import matplotlib.pyplot as plt
import beautifulsoup4 as bs

When I execute it, I get the following error, seemingly indicating that the beautifulsoup4 package is not installed…..

DangerZone:test09-playwithnumpyandscipy bruce$ python3 main.py
Traceback (most recent call last):
  File "main.py", line 3, in <module>
    import beautifulsoup4 as bs
ModuleNotFoundError: No module named 'beautifulsoup4'

Yet, when I request a "list" of installed modules from pip3, i get the following....

DangerZone:test09-playwithnumpyandscipy bruce$ pip3 list
beautifulsoup4 (4.6.0)
certifi (2017.7.27.1)
chardet (3.0.4)
cycler (0.10.0)
idna (2.5)
inflection (0.3.1)
matplotlib (2.0.2)
more-itertools (3.2.0)
numpy (1.13.1)
pandas (0.20.3)
pip (9.0.1)
pyparsing (2.2.0)
python-dateutil (2.6.1)
pytz (2017.2)
Quandl (3.2.0)
requests (2.17.3)
scikit-learn (0.19.0)
scipy (0.19.1)
setuptools (28.8.0)
six (1.10.0)
sklearn (0.0)
urllib3 (1.21.1)

Seems that beautifulsoup4 is installed, so why the earlier error? What am I doing wrong?

I've always found this one a bit weird, because the name of the library is 'BeautifulSoup4'. However, the proper way to import it is:

from bs4 import BeautifulSoup as bs

Making the Soup (documentation)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM