我安装了bs4,但得到“没有名为'bs4'的模块”

2024-06-26 14:07:09 发布

您现在位置:Python中文网/ 问答频道 /正文

更新:感谢所有回答和评论的人。我现在知道我已经安装了2个版本的python。我的程序是从“Miniconda3/python.exe”运行的。而bs4安装在“c:\python38\lib\site包”中。我理解这是问题的原因。我删除了Minicoda3,但VS代码在我运行程序时仍尝试使用它。我怎样才能解决这个问题

当我运行以下代码时:

>>> from bs4 import BeautifulSoup

错误:

I get the error: "No module named 'bs4'. 
After I install bs4, It says "Requirement already satisfied" yet I get the same error.

我不确定我做错了什么,请帮忙。下面是错误消息

PS C:\Users\Admin\Desktop\exAPP> pip install bs4
Collecting bs4
Requirement already satisfied: beautifulsoup4 in c:\python38\lib\site-packages (from bs4) (4.9.1)
Requirement already satisfied: soupsieve>1.2 in c:\python38\lib\site-packages (from beautifulsoup4->bs4) (2.0.1)     
Using legacy setup.py install for bs4, since package 'wheel' is not installed.
Installing collected packages: bs4
Successfully installed bs4-0.0.1
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
  File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
    import BeautifulSoup
ModuleNotFoundError: No module named 'BeautifulSoup'
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
  File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
    from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
PS C:\Users\Admin\Desktop\exAPP>

Tags: infrompyadminexeuserspsmodule
2条回答

您正在使用miniconda,它可能不在正确的路径上,因此pip实际上是单独Python安装的一部分

您可以使用conda install pipC:/Users/Admin/Miniconda3/python.exe -m pip install bs4

好的,我的问题已经解决了,我的程序正在运行。正如我在更新中所说,第一个问题是由于安装了2个版本的python。在我删除了不需要的版本后,它仍然被设置为python解释器路径。我试图通过进入VS代码设置来解决这个问题,但是运气不好。幸运的是,我终于注意到屏幕左下角有一个按钮,可以让我轻松地更改路径。再次感谢那些评论和回答的人

相关问题 更多 >