[英]ModuleNotFoundError: No module named 'bs4' but installed correctly using PIP3 on Python 3.8.5
Sorry I know this question has come up a bit but I am stumped.抱歉,我知道这个问题已经出现了一点,但我很难过。 Previously working fine code is now no longer working.以前工作良好的代码现在不再工作。 I have tried uninstalling and reinstalling python 3.8.5, setting up new environments, stripping the code back to basics.我尝试卸载并重新安装 python 3.8.5,设置新环境,将代码剥离回基础。 I've installed and uninstalled BS4 and Beautifulsoup4 dozens of times.我已经安装和卸载了数十次 BS4 和 Beautifulsoup4。
My method is pip3 install bs4
我的方法是pip3 install bs4
The installation goes fine but when I run the code I get安装很顺利,但是当我运行代码时,我得到了
File "/Users/rupertdenton/Desktop/Coding/Anybody/tester.py", line 1, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
I triple check python version and it is 3.8.5 and reinstall again with success:我三次检查 python 版本,它是 3.8.5 并再次成功安装:
Requirement already satisfied: soupsieve>1.2 in ./venv/lib/python3.8/site-packages (from beautifulsoup4->bs4) (2.0.1)
Installing collected packages: beautifulsoup4, bs4
Successfully installed beautifulsoup4-4.9.1 bs4-0.0.1
But still the code throws the same error.但是代码仍然抛出相同的错误。 Here is the pared back code which worked fine until about a week ago.这是大约一周前运行良好的精简代码。
from bs4 import BeautifulSoup
def scrapecafes(city, area):
#url = 'https://www.broadsheet.com.au/melbourne/guides/best-cafes-thornbury' #go to the website
url = f"https://www.broadsheet.com.au/{city}/guides/best-cafes-{area}"
response = requests.get(url, timeout=5)
soup_cafe_names = BeautifulSoup(response.content, "html.parser")
type(soup_cafe_names)
cafeNames = soup_cafe_names.findAll('h2', attrs={"class":"venue-title", }) #scrape the elements
cafeNamesClean = [cafe.text.strip() for cafe in cafeNames]
if your code is depending on the environment, you need to activate the environment first.如果你的代码依赖于环境,你需要先激活环境。
. env/bin/activate
if env
is the name of your environment.如果env
是您环境的名称。
Then然后
pip3 install bs4 requests
Then run your program.然后运行你的程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.