I'm working in Python and using Flask. When I run my main Python file on my computer, it works perfectly, but when I activate venv and run the Flask Python file in the terminal, it says that my main Python file has "No Module Named bs4." Any comments or advice is greatly appreciated.
19 Answers
Activate the virtualenv, and then install BeautifulSoup4:
$ pip install BeautifulSoup4
When you installed bs4
with easy_install
, you installed it system-wide. So your system python can import it, but not your virtualenv python.
If you do not need bs4
to be installed in your system python path, uninstall it and keep it in your virtualenv.
For more information about virtualenvs, read this
I have been searching far and wide in the internet.
I'm using Python 3.6 and MacOS. I have uninstalled and installed with pip3 install bs4
but that didn't work. It seems like python is not able to detect or search the bs4
module.
This is what worked:
python3 -m pip install bs4
The -m
option allows you to add a module name.
Addendum to the original query: modules.py
help('modules')
$python modules.py
It lists that module bs4 already been installed.
_codecs_kr blinker json six
_codecs_tw brotli kaitaistruct smtpd
_collections bs4 keyword smtplib
_collections_abc builtins ldap3 sndhdr
_compat_pickle bz2 lib2to3 socket
Proper solution is:
pip install --upgrade bs4
Should solve the problem.
Not only that, it will show same error for other modules as well. So you got to issue the pip command same way as above for those errored module(s).