k1051785839
2017-09-14 08:55
采纳率: 100%
浏览 1.5k

python 爬虫刚开始学习的一个问题

图片说明
这段代码,当我点Execute Selection in Console时候,可以正常运行,并且结果和教材一致
图片说明
但是我直接运行这个文件时,就开始报错了
图片说明
这是怎么回事呢??
错误信息如下:
C:\Users\yzy\AppData\Local\Programs\Python\Python36\python.exe C:/Users/yzy/Desktop/python/webscraping.py
Traceback (most recent call last):
File "C:\Users\yzy\AppData\Local\Programs\Python\Python36\lib\bz2.py", line 19, in
from threading import RLock
ImportError: cannot import name 'RLock'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/yzy/Desktop/python/webscraping.py", line 4, in
from urllib.request import urlopen
File "C:\Users\yzy\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 98, in
import tempfile
File "C:\Users\yzy\AppData\Local\Programs\Python\Python36\lib\tempfile.py", line 43, in
import shutil as shutil
File "C:\Users\yzy\AppData\Local\Programs\Python\Python36\lib\shutil.py", line 22, in
import bz2
File "C:\Users\yzy\AppData\Local\Programs\Python\Python36\lib\bz2.py", line 21, in
from dummy_threading import RLock
File "C:\Users\yzy\AppData\Local\Programs\Python\Python36\lib\dummy_threading.py", line 49, in
sys_modules['_dummy
_threading_local'] = sys_modules['_threading_local']
KeyError: '_threading_local'
Exception ignored in:
AttributeError: module 'threading' has no attribute '_shutdown'

Process finished with exit code 1

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • 连小胖 2017-09-15 03:05
    已采纳

    你自己建的py文件起名字不要和python的包名一样!问题应该出在这里,你自己写的threading.py文件把python的threading覆盖了

    点赞 评论
  • T_world 2017-09-14 10:59

    看报错信息似乎是引入urlopen模块的时候出了问题,我一般是这么用的(python2.7)

     import urllib
     html = urllib.urlopen('xxxxxxx')
    
    点赞 评论
  • k1051785839 2017-09-15 01:40

    好的,我看一看,谢谢

    点赞 评论
  • 连小胖 2017-09-15 03:05

    图片说明

    点赞 评论

相关推荐 更多相似问题