visual-studio - ImportError:在终端中运行时没有名为 bs4 的模块
问题描述
我正在尝试通过终端运行 python 脚本,但不断收到以下错误:
'''
Traceback (most recent call last):
File "note9.py", line 1, in <module>
from bs4 import BeautifulSoup
ImportError: No module named bs4
'''
我已经尝试卸载 bs4 并重新安装 bs4。
奇怪的是我能够在 Visual Studio 代码中运行脚本。
'''
User:PythonProjects username$ /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 /Users/username/Desktop/PythonProjects/note9.py
Unavailable
'''
为什么我在尝试通过终端运行脚本时收到错误消息?
from bs4 import BeautifulSoup
from requests import get
import yagmail
def lovely_soup(u):
r = get(u, headers={
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1'})
return BeautifulSoup(r.text, 'lxml')
url = 'https://www.baka.ca/Samsung/Samsung-Galaxy-Note-9-128GB-LTE-Blue'
soup = lovely_soup(url)
for h2 in soup.find_all('h2'):
if 'Unavailable' in h2.text:
yagmail.SMTP('mygmailusername').send('to@someone.com', 'subject', contents)
print('Unavailable')
else:
yagmail.SMTP('mygmailusername').send('to@someone.com', 'subject', contents)
print('Available')
'''
以下是我在终端运行时收到的错误
Tylers-MacBook-Air-2:PythonProjects tylerarie$ python note9.py
Traceback (most recent call last):
File "note9.py", line 1, in <module>
from bs4 import BeautifulSoup
ImportError: No module named bs4
Tylers-MacBook-Air-2:PythonProjects tylerarie$ pip3 install bs4
Requirement already satisfied: bs4 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (0.0.1)
Requirement already satisfied: beautifulsoup4 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from bs4) (4.8.1)
Requirement already satisfied: soupsieve>=1.2 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from beautifulsoup4->bs4) (1.9.5)
Tylers-MacBook-Air-2:PythonProjects tylerarie$
它确实说该模块已安装?为什么我不能在终端运行这个脚本!!!???
该脚本在 VSC 中运行良好。
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Tylers-MacBook-Air-2:PythonProjects tylerarie$ /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 /Users/tylerarie/Desktop/PythonProjects/note9.py
Unavailable
Tylers-MacBook-Air-2:PythonProjects tylerarie$
解决方案
推荐阅读
- encryption - FSM 问题 vhdl AES 加密未进入第三状态?
- python - 使用 Python 获取页面加载时间
- java - 如何在不同的环境(开发、测试、生产)中维护相同的数据表?
- ios - 自定义表格单元格中的堆栈视图
- validation - 如何在 TYPO3 FlexForms 中进行评估并防止保存无效输入
- r - 将绘图分配给循环中的变量
- sql - 如何将不同年份同一月份的数据分开?
- elasticsearch - 我们如何使用 elasticsearch 来处理时间序列数据?我想将 Elastic-Stack 作为一个整体用于时间序列数据
- python - ProcessPoolExecutor:进程池中的一个进程在future正在运行或挂起时突然终止
- python - Flask socket IO 从另一个模块发出