我已经安装了bs4,并且在这样的cmd中效果很好
C:\Users\Ronium>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup('<p>Hello</p>','html.parser')
>>> soup.find('p').text
'Hello'
但是当我将其导入py时。文件给我一个错误
O:\Unify\WebScrapper>Graphics.py
Traceback (most recent call last):
File "O:\Unify\WebScrapper\Graphics.py", line 2, in <module>
from bs4 import BeautifulSoup as soup
ModuleNotFoundError: No module named 'bs4'
添加: python实际上也在O:\中工作
O:\Unify\WebScrapper>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup as soup
>>> soup = soup('<p>Hello</p>', 'html.parser')
>>> soup.find('p').text
'Hello'
>>>
答案 0 :(得分:0)
运行python脚本时,您位于另一个驱动器“ O:\”中。
确保在O:\驱动器中安装了python,或者从C:\驱动器中运行python文件,它应该可以工作!
答案 1 :(得分:0)
我认为我已经解决了这个问题,因为当我尝试运行py时,我的电脑中也安装了python 3.7。文件实际上执行了未安装bs4的3.7版本。
谢谢你们