python3 中没有名为“beautifulsoup4”的模块

新手上路,请多包涵
$ virtualenv test
$ source test/bin/activate
$ pip3 install beautifulsoup4

现在脚本 test.py

 import urllib.request
import sys
import unittest, time, re

import requests
from bs4 import BeautifulSoup

class Sel(unittest.TestCase):

    def setUp(self):
        self.base_url = "file:///Users/ishandutta2007/Desktop/cars/cars-price-list.html"

    def test_sel(self):
        with urllib.request.urlopen(self.base_url) as url:
            html_source = url.read()
        data = html_source#.encode('utf-8')
        parsed_html = BeautifulSoup(data, 'html.parser')

if __name__ == "__main__":
    unittest.main()

当我运行 $python3 test.py

文件“test.py”,第 6 行,来自 bs4 import BeautifulSoup ModuleNotFoundError: No module named ‘bs4’

然后尝试

from beautifulsoup4 import BeautifulSoup

文件“test.py”,第 6 行,在 from beautifulsoup4 import BeautifulSoup ModuleNotFoundError: No module named ‘beautifulsoup4’

要求清楚地表明两者

$ pip3 freeze > requirements.txt
$ cat requirements.txt
beautifulsoup4==4.6.0
certifi==2018.1.18
chardet==3.0.4
idna==2.6
requests==2.18.4
urllib3==1.22

原文由 ishandutta2007 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 790
1 个回答

只安装 BeautifulSoup4 而不是 bs4BeautifulSoup 然后,

做这个:

 from bs4 import BeautifulSoup

原文由 Abdullah Ahmed Ghaznavi 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题