2 k1051785839 k1051785839 于 2017.09.14 16:55 提问

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个回答

lianxiaopang
lianxiaopang   2017.09.15 11:05
已采纳

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

lianxiaopang
lianxiaopang 回复k1051785839: 不客气,这些问题我也犯过,多注意就行了
2 个月之前 回复
k1051785839
k1051785839 谢谢,知道了
2 个月之前 回复
lianxiaopang
lianxiaopang   2017.09.15 11:05

图片说明

k1051785839
k1051785839 谢谢你!已经解决了!
2 个月之前 回复
Runner__1
Runner__1   Rxr 2017.09.14 18:59

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

 import urllib
 html = urllib.urlopen('xxxxxxx')
Runner__1
Runner__1 sorry,sorry,刚注意到你用的是python3,不过引用方法似乎是一样的,参考这篇博客:http://www.cnblogs.com/lyhc/p/5859976.html
2 个月之前 回复
k1051785839
k1051785839   2017.09.15 09:40

好的,我看一看,谢谢

Csdn user default icon
上传中...
上传图片
插入图片