Cannot import Beautiful Soup

The issue was I named the file HTMLParser.py , and that name is already used somewhere in the bs4 module.

Thanks to everyone that helped!


Make sure the directory from which you are running your script does not contain a filename called bs4.py.


I experienced a variation of this problem and am posting for others' benefit.

I named my Python example script bs4.py

Inside this script, whenever trying to import bs4 using the command:

from bs4 import BeautifulSoup, an ImportError was thrown, but confusingly (for me) the import worked perfectly from an interactive shell within the same venv environment.

After renaming the Python script, imports work as expected. The error was caused as Python tries to import itself from the local directory rather than using the system copy of bs4