我在Mac上,并且在终端上运行2.X,在IDE上运行3.X(如果出于某种原因这很重要)。
所以我想开始网上抓取,以便获得美丽的汤。
我安装了自制软件,所以我可以开始安装pip(即使由于某些原因我已经使用python一段时间,以前也没有安装它)
我跑了brew install pip3
,然后我跑了sudo pip install beatifulsoup4
要检查是否确实安装了beatifulsoup,我在终端上输入了python并输入了from bs4 import BeautifulSoup
。接下来,我输入BeautifulSoup
,然后返回<class 'bs4.BeautifulSoup'>
。
所以这意味着BeautifulSoup已安装,并且我准备将其导入我的IDE中,对吗?
不。当我在终端机(from bs4 import BeautifulSoup
)上键入完全相同的行时,将返回以下内容:
Traceback (most recent call last):
File "/Users/MinecraftMaster/Desktop/help.py", line 1, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
这没有道理。为什么我可以在终端上导入模块,而不能在IDE上导入模块?
我的sys.path
:
Terminal 2.X Sys.Path:
['', '/Library/Python/2.7/site-packages/requests-2.21.0-py2.7.egg', '/Library/Python/2.7/site-packages/certifi-2018.11.29-py2.7.egg', '/Library/Python/2.7/site-packages/urllib3-1.24.1-py2.7.egg', '/Library/Python/2.7/site-packages/idna-2.8-py2.7.egg', '/Library/Python/2.7/site-packages/chardet-3.0.4-py2.7.egg', '/Library/Python/2.7/site-packages/beautifulsoup4-4.7.1-py2.7.egg', '/Library/Python/2.7/site-packages/pip-18.1-py2.7.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']
Terminal 3.X Path:
['', '/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages']
IDE Sys.Path:
['/Users/HomeFolder/Desktop', '/Users/HomeFolder/Documents', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']