我安装了Python 3.x(除了Ubuntu上的Python 2.x)并慢慢开始配对我在Python 2.x中使用的模块.
所以我想知道,对于Python 2.x和Python 3.x,我应该采用什么方法让pip变得简单?
$ virtualenv test
$ source test/bin/activate
$ pip3 install beautifulsoup4
Run Code Online (Sandbox Code Playgroud)
现在脚本 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()
Run Code Online (Sandbox Code Playgroud)
当我跑 $python3 test.py
文件“test.py”,第 6 行,在 from bs4 import BeautifulSoup ModuleNotFoundError: No module named 'bs4'
然后尝试
from beautifulsoup4 import BeautifulSoup
Run Code Online (Sandbox Code Playgroud)
文件“test.py”,第 6 行,在 from beautifulsoup4 import …