簡體   English   中英

在python3中導入BeautifulSoup時出錯

[英]Error when importing BeautifulSoup in python3

我使用以下命令安裝了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嗎?

BeautifulSoup將顯示為beautifulsoup4

提到問題,如果我安裝並檢查,則該模塊名稱應可用

[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']
>>> 

如果無法使用打包程序安裝,請嘗試使用pip安裝

pip3 install beautifulsoup4

文檔中查看

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM