我在win7下运行python 3.4。
如果没有'import matplotlib',为什么'import urllib'失败?
import urllib
import socket
import sys, os
import matplotlib.pyplot # urllib won't work unless this is here ! WTF?? !
url='https://finance.yahoo.com/quote/SPY/history?period1=1410652800&period2=1536883200&interval=1d'
bytes = urllib.request.urlopen(url, timeout=4).read()
page = str( bytes, encoding='utf8' )
print("Page length="+str(len(page)))
sys.exit
如果不导入matplotlib.pyplot,程序将失败,并出现以下错误:
File "C:\Python34\minibigdrops.py", line 8, in module
bytes = urllib.request.urlopen(url, timeout=4).read()
AttributeError: 'module' object has no attribute 'request'
其他属性,如“error”,也找不到。
我看到其他几个人在urllib上发布了问题。或许他们也可以尝试导入matplotlib。