需要帮助处理Python2.7和Python3上的beautifulsoup错误吗

需要帮助处理Python2.7和Python3上的beautifulsoup错误吗,python,python-3.x,python-2.7,beautifulsoup,Python,Python 3.x,Python 2.7,Beautifulsoup,我正在尝试设置BeautifulSoup4,以便运行以下操作: from bs4 import BeautifulSoup Defaulting to user installation because normal site-packages is not writeable. Requirement already satisfied: beautifulsoup4 in ./Library/Python/2.7/lib/python/site-packages (4.8.2) Requ

我正在尝试设置BeautifulSoup4,以便运行以下操作:

from bs4 import BeautifulSoup
Defaulting to user installation because normal site-packages is not writeable. 
Requirement already satisfied: beautifulsoup4 in ./Library/Python/2.7/lib/python/site-packages (4.8.2)
Requirement already satisfied: soupsieve>=1.2 in ./Library/Python/2.7/lib/python/site-packages (from beautifulsoup4) (1.9.5)
Requirement already satisfied: backports.functools-lru-cache; python_version < "3" in ./Library/Python/2.7/lib/python/site-packages (from soupsieve>=1.2->beautifulsoup4) (1.6.1)

$ from bs4 import BeautifulSoup4
from: can't read /var/mail/bs4
但是,当我安装BeautifulSoup4时,我得到以下信息:

from bs4 import BeautifulSoup
Defaulting to user installation because normal site-packages is not writeable. 
Requirement already satisfied: beautifulsoup4 in ./Library/Python/2.7/lib/python/site-packages (4.8.2)
Requirement already satisfied: soupsieve>=1.2 in ./Library/Python/2.7/lib/python/site-packages (from beautifulsoup4) (1.9.5)
Requirement already satisfied: backports.functools-lru-cache; python_version < "3" in ./Library/Python/2.7/lib/python/site-packages (from soupsieve>=1.2->beautifulsoup4) (1.6.1)

$ from bs4 import BeautifulSoup4
from: can't read /var/mail/bs4
默认为用户安装,因为普通站点包不可写。
已满足要求:beautifulsoup4 in./Library/Python/2.7/lib/Python/site-packages(4.8.2)
已满足要求:soupsieve>=1.2in./Library/Python/2.7/lib/Python/site-packages(来自beautifulsoup4)(1.9.5)
已满足要求:backports.functools-lru-cache;python_版本=1.2->beautifulsoup4)(1.6.1)
来自bs4进口的美元4
发件人:无法读取/var/mail/bs4
在Python3中运行时,我遇到了这个错误

Python 3.8.2 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import beautifulsoup4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'beautifulsoup4' from 'bs4' (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/bs4/__init__.py)
Python 3.8.2
关于达尔文的[Clang 6.0(Clang-600.0.57)]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>从bs4导入到bs4
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:无法从“bs4”导入名称“beautifulsoup4”(/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site packages/bs4/\u init\u.py)
我的计算机上有Python3和Python2.7,但不知道如何让它识别bs4


谢谢你的建议

在一个系统上安装多个版本的Python可能会导致混乱,这是每个Python开发人员都会遇到的问题

要解决您的问题,请尝试使用
python-m
命令安装
bs4
,例如
python-m pip安装beautifulsoup4
。这将确保pip将包安装到您调用的python中

听起来也是时候学习了。虚拟环境允许您为每个项目分离python实例,这样就不会在包之间产生冲突


如果您想了解有关使用多个版本的python安装BeautifulSoup4的更多信息。

您是如何安装BeautifulSoup的?使用pip或其他东西?这不是安装包并使用不同的Python安装运行程序的典型问题吗?我建议您使用虚拟环境。是的,我是通过PIP添加的。这是否回答了您的问题?