更新:感谢所有回复和评论的人。我现在知道我已经安装了两个版本的python。我的程序是从"Miniconda3/python.exe“运行的。而bs4安装在"c:\python38\lib\site-packages“中。我知道这是问题的原因。我删除了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>发布于 2020-07-25 01:09:17
您正在使用miniconda,它可能不在您的路径上,因此pip实际上是单独的Python安装的一部分。
您可以使用conda install pip或C:/Users/Admin/Miniconda3/python.exe -m pip install bs4
发布于 2020-07-25 03:13:36
好了,我的问题已经解决了,我的程序正在运行。正如我在更新中所说的,第一个问题是由于安装了两个版本的python。在我删除了不需要的版本后,它仍然被设置为python解释器路径。我试图通过进入VS代码设置来解决这个问题,但没有成功。幸运的是,我终于注意到在屏幕的左下角有一个按钮,可以让我轻松地更改路径。再次感谢那些评论和回答的人。
https://stackoverflow.com/questions/63078190
复制相似问题