【发布时间】:2018-08-16 15:19:50
【问题描述】:
$ 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 行,在 from 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
【问题讨论】:
-
也许这有帮助? stackoverflow.com/questions/34507744/… 检查 pip freeze 是否真的安装了。
-
用
bs4替换beautifulsoup4 -
@codekaizer 检查更新
标签: python python-3.x beautifulsoup