python3.7导入BeautifulSoup报错

python3.7导入BeautifulSoup报错

    • python2.7导入BeautifulSoup
    • 将pycharm的项目解释器由python2.7更换为python3.7,BeautifulSoup包报错

之前使用python2.7时,PyCharm用快捷键Alt+Enter就可以轻松导入BeautifulSoup;但是将项目解释器变为python3.7后,需要导入BeautifulSoup4

python2.7导入BeautifulSoup

当python版本为2.7时,使用BeautifulSoup时,在PyCharm中使用快捷键Alt+Eneter,自动导入成功from bs4 import BeautifulSoup

将pycharm的项目解释器由python2.7更换为python3.7,BeautifulSoup包报错

1、将PyCharm的项目解释器由python2.7更换为python3.7
PyCharm -> preferences -> Project Interpreter -> Python 3.7
2、运行,报错:ModuleNotFoundError: No module named ‘bs4’
3、在PyCharm中使用快捷键Alt+Eneter:Install Package BeautifulSoup
安装失败,点开详细:SyntaxError: Missing parentheses in call to ‘print’. Did you mean print(“Unit tests have failed!”)?
4、尝试另一种方式安装BeautifulSoup:
PyCharm -> preferences -> Project Interpreter -> Python 3.7 点击左下角+,Install beautifulsoup4,勾选Install to user’s site packages directory,点击Install Package
python3.7导入BeautifulSoup报错_第1张图片
python3.7导入BeautifulSoup报错_第2张图片
5、发现Beautifulsoup4已经安装成功,点击OK
6、再次运行,发现已经OK

你可能感兴趣的:(python)