电脑中装了python3、python2和anaconda
写了一个简单的小程序(My1stCrawler.py)如下:
import requests,bs4,webbrowser,sys res=requests.get('https://www.baidu.com/s?wd='+' '.join(sys.argv[1:])) res.raise_for_status() print(sys.argv[1:]) soup=bs4.BeautifulSoup(res.text) linkElems=soup.select('.r a') print(linkElems) numOpen=min(5,len(linkElems)) for i in range(numOpen): webbrowser.open(linkElems[i].get('href'))
在命令行中运行My1stCrawler.py Trump
,预期是会打开相应的搜索页面。可是提示提示“No module named requests
”。可我之前是安装过requests的包的。
在命令行中输入python
,再输出import requests
,顺利执行
用pip安装的话又会提示已经安装了。情况如下:
和requests没有关系,很多库都会遇到这个问题。
困扰了好久,来这里求助
另外,python3、2和anaconda都已经加到系统环境变量中了
Try running like this:
All versions have been added to the environment variables, but I don’t know which one to use. Your problem may be caused by the difference between the Python version of the .py file and the version preferred by the command line.