我使用以下命令安装了bs4:
sudo apt-get install python3-bs4
但是当我尝试导入BeautifulSoup时,我收到此错误:
Traceback (most recent call last):
File "bsExample.py", line 1, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
我不确定为什么会发生这种情况,因为我刚刚安装了bs4。有谁知道我为什么会得到ModuleNotFoundError?
答案 0 :(得分:0)
BeautifulSoup将显示为beautifulsoup4
参考this问题,如果我安装并检查,它应该与该模块名称一起提供
[abcd@ES-CO-abcd ~]$ sudo python -m pip install bs4
[sudo] password for abcd:
Collecting bs4
Downloading bs4-0.0.1.tar.gz
Collecting beautifulsoup4 (from bs4)
Downloading beautifulsoup4-4.6.0-py3-none-any.whl (86kB)
100% |████████████████████████████████| 92kB 920kB/s
Installing collected packages: beautifulsoup4, bs4
Running setup.py install for bs4 ... done
Successfully installed beautifulsoup4-4.6.0 bs4-0.0.1
[abcd@ES-CO-abcd ~]$ python
Python 3.6.2 (default, Jul 20 2017, 03:52:27)
[GCC 7.1.1 20170630] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>>
>>>
>>>
>>> import pip
>>> installed_packages = pip.get_installed_distributions()
>>> installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
... for i in installed_packages])
>>> print(installed_packages_list)
['appdirs==1.4.3', 'beaker==1.8.1', 'beautifulsoup4==4.6.0', 'bs4==0.0.1', 'chardet==3.0.4', 'cupshelpers==1.0', 'docopt==0.6.2', 'httpie==0.9.9', 'idna==2.6', 'iotop==0.6', 'keyutils==0.5', 'lightdm-gtk-greeter-settings==1.2.1', 'louis==3.3.0', 'mako==1.0.7', 'markupsafe==1.0', 'mugshot==0.3.2', 'npyscreen==4.10.5', 'packaging==16.8', 'pacman-mirrors==4.2.3', 'pexpect==4.2.1', 'pip==9.0.1', 'psutil==5.3.1', 'ptyprocess==0.5.2', 'pycairo==1.13.3', 'pycups==1.9.73', 'pycurl==7.43.0', 'pygments==2.2.0', 'pygobject==3.24.1', 'pyparsing==2.2.0', 'python-distutils-extra==2.39', 'python-xapp==1.0.0', 'pyxdg==0.25', 'pyyaml==3.12', 'requests==2.18.4', 'setproctitle==1.1.10', 'setuptools==36.4.0', 'six==1.10.0', 'team==1.0', 'udiskie==1.7.0', 'urllib3==1.22']
>>>
答案 1 :(得分:0)