ImportError: No Module Named bs4 (BeautifulSoup)

寵の児 提交于 2019-12-17 04:55:28

问题


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.


回答1:


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




回答2:


For python2.x:

sudo pip install BeautifulSoup4

For python3:

sudo apt-get install python3-bs4



回答3:


Just tagging onto Balthazar's answer. Running

pip install BeautifulSoup4

did not work for me. Instead use

pip install beautifulsoup4



回答4:


If you use Pycharm, go to preferences - project interpreter - install bs4. If you try to install BeautifulSoup, it will still show that no module named bs4.




回答5:


I will advise you to uninstall the bs4 library by using this command:

pip uninstall bs4

and then install it using this command:

sudo apt-get install python3-bs4

I was facing the same problem in my Linux Ubuntu when I used the following command for installing bs4 library:

pip install bs4




回答6:


pip3 install BeautifulSoup4

Try this. It works for me.




回答7:


If you are using Anaconda for package management, following should do:

conda install -c anaconda beautifulsoup4




回答8:


The easiest is using easy_install.

easy_install bs4 

It will work if pip fails.




回答9:


Try this:

sudo python3 -m pip install bs4



回答10:


pip3.7 install bs4

Try this. It works with python 3.7




回答11:


pip install --user BeautifulSoup4




回答12:


A lot of tutorials/references were written for Python 2 and tell you to use pip install somename. If you're using Python 3 you want to change that to pip3 install somename.



来源:https://stackoverflow.com/questions/11783875/importerror-no-module-named-bs4-beautifulsoup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!