简体   繁体   English

ModuleNotFoundError:没有名为“bs4”的模块,但在 Python 3.8.5 上使用 PIP3 正确安装

[英]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.

相关问题 ModuleNotFoundError: 没有安装了 bs4 并在 cmd 中工作的名为“bs4”的模块 - ModuleNotFoundError: No module named 'bs4' with bs4 installed and worked in cmd ModuleNotFoundError:没有名为 bs4 的模块 - ModuleNotFoundError: no module named bs4 ModuleNotFoundError:没有名为“bs4”的模块 - ModuleNotFoundError: No module named 'bs4' ModuleNotFoundError:没有模块名为“ bs4”,但我安装了bs4,我相信 - ModuleNotFoundError: No module named 'bs4' but I have bs4 installed I believe ModuleNotFoundError: No module named &#39;psycopg2&#39; (python3, mac, pip3 显示 psycopg2 已成功安装) - ModuleNotFoundError: No module named 'psycopg2' (python3, mac, pip3 shows psycopg2 successfully installed) 导入 bs4 ModuleNotFoundError:没有名为“bs4”的模块 - import bs4 ModuleNotFoundError: No module named 'bs4' 如何修复 ModuleNotFoundError:没有名为 bs4 的模块 - how to fix ModuleNotFoundError: no module named bs4 ModuleNotFoundError:没有名为“bs4”Atom MacOS 的模块 - ModuleNotFoundError: No module named 'bs4' Atom MacOS ModuleNotFoundError:没有名为“bs4”的模块 [崇高文本 3] - ModuleNotFoundError: No module named 'bs4' [sublime text 3] ModuleNotFoundError:heroku 中没有名为“bs4”的模块 - ModuleNotFoundError: No module named 'bs4' in heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM