python3:出错!this inspection detects names that should resolve but don't.due to dynamic dispatch and d

初学爬虫,就遇到一个特别傻的错误,搞了大半个小时,终于知道问题所在了。

this inspection detects names that should resolve but don't.due to dynamic dispatch and duck typing,this is possible in a limited but useful number of cases .top-level and class-level items are supported better than instance items

错误意思为:import的类urllib不在python库中。

.py代码如下:

from  urllib import request
'''
使用urllib.request请求一个网页内容,并把内容打印出来
'''

if __name__ == '__main__':

    url = "https://blog.csdn.net"
    # 打开相应url并把相应页面作为返回
    rsp = request.urlopen(url)

    # 把返回结果读取出来,读取出来内容类型为bytes
    html = rsp.read()
    print(type(html))

    # 如果想把bytes内容转换成字符串,需要解码
    html = html.decode("utf-8")
    print(html)

是因为使用pycharm,配置的python解释器出现了问题。如下:

重新配置python解释器就可以。

配置方式如下:

(1)file->settings打开

(2)点击左边的目录后,点击右侧齿轮。

(3)选择anaconda中的python解释器

(4)耐心等待配置完后,点击OK即可。

学编程的道路就是这样,磕磕碰碰,有时候因为一个小小的问题而纠结很久。有个老师曾跟我讲过,不管遇到什么样的问题,总能解决的。我一直坚信这一点,相信和我一样在学习编程的你们,也可以顺利的解决遇到的problems~

猜你喜欢

转载自blog.csdn.net/sunshine_lyn/article/details/81174426