命令在Python(命令行)中工作,但不在.py文件中

时间:2017-07-15 20:23:35

标签: python web-scraping beautifulsoup python-requests

我一直在尝试使用Python学习网页抓取。我按照一些YouTube视频的说明进行操作。他们从:

开始
import requests
from bs4 import BeautifulSoup

这适用于Python命令行(Python.exe),但不适用于我的文件。我认为它有效,因为它没有给我一个错误。当我运行.py文件时,我收到此错误:

Traceback (most recent call last):
  File "Path\Web-Scrapy.py", line 1, in <module>
    import requests
ImportError: No module named 'requests'

我的第一个猜测是我没有安装请求模块,但是当我运行pip install requests时,我收到了这个:

C:\Python34\Scripts>pip install requests
Requirement already satisfied: requests in c:\python34\lib\site-packages
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\python34\lib\site-pac
kages (from requests)
Requirement already satisfied: idna<2.6,>=2.5 in c:\python34\lib\site-packages (
from requests)
Requirement already satisfied: urllib3<1.22,>=1.21.1 in c:\python34\lib\site-pac
kages (from requests)
Requirement already satisfied: certifi>=2017.4.17 in c:\python34\lib\site-packag
es (from requests)

请帮助我,为什么我会收到此错误?

0 个答案:

没有答案