modulenotfounderror: no module named 'bs4'
Short answer: install the beautifulsoup4 distribution (not a package called bs4) into the same interpreter that runs your code. ``` ModuleNotFoundError: No module named 'bs4' ``` 1.
Short answer: install the beautifulsoup4 distribution (not a package called bs4) into the same interpreter that runs your code. `` ModuleNotFoundError: No module named 'bs4' 1. Run python -m pip install beautifulsoup4. Using python -m pip guarantees the package lands in the interpreter you actually run. Expected: install completes and lists beautifulsoup4 plus soupsieve. 2. Verify with python -c "from bs4 import BeautifulSoup; print('ok')". Expected: ok. 3. If it still fails, compare interpreters: python -c "import sys; print(sys.executable)" and python -m pip --version should point at the same environment. In a virtualenv, activate it before installing. In an IDE, select that same interpreter as the project interpreter. 4. Avoid the trap package: pip install bs4 installs a tiny placeholder distribution that does not provide BeautifulSoup. If you installed it by mistake, run python -m pip uninstall bs4` and then repeat step 1. Root cause: bs4 is not part of the standard library and was never installed for this interpreter, or it was installed for a different one. The import name being shorter than the distribution name is what sends people to the wrong install command. When to use: fresh environments, CI images, new virtualenvs, Jupyter kernels pointing at another env. When NOT to use: if the import works but parsing fails with a FeatureNotFound tree-builder error, that is a missing parser (lxml or html5lib), not a missing bs4. Variant phrasings: "no module named bs4", "from bs4 import beautifulsoup error", "import bs4 could not be resolved". Edge cases: on Debian/Ubuntu the system package is python3-bs4 if you must use apt. In Jupyter, install with the notebook kernel's interpreter or restart the kernel after installing. Check there is no local file named bs4.py shadowing the package.
Context: The import name and the install name differ here, and that mismatch is the whole problem. Code imports the bs4 module, but the PyPI distribution that provides it is called beautifulsoup4. On top of that, pip often installs into a different interpreter than the one running the script, especially with several Pythons, a virtualenv, or an IDE with its own interpreter setting. The error means the running interpreter has no bs4 in its site-packages at all.