python报错集合
学习python过程中的调错总结
咕噜oo
我们往往低估了一年内能做的事,却高估了十年后能做的事——万丈高楼平地起。
展开
-
解决ImportError: attempted relative import with no known parent package
当前路径下导包:from . import util发现报错:执行文件异常:ImportError: attempted relative import with no known parent package解决:不使用当前路径,改为绝对路径:from textrank4zh import util问题解决。原创 2021-07-05 17:14:52 · 1836 阅读 · 0 评论 -
jupyter中interrupt the kernel(中断)没有反应
有的时候,程序运算量很大或者陷入死循环时,点击interrupt(中断)按钮没有反应时,可以有三种解决方案:1.终端输入Ctrl+c,退出jupyter2.选中notebook,shutdown3.点击restartthekernel(推荐)...原创 2021-06-25 17:07:23 · 8231 阅读 · 1 评论 -
爬虫报错:During handling of the above exception, another exception occurred和TimeoutError
错误一:During handling of the above exception, another exception occurred:在处理上述异常期间,发生了另一个异常。造成这个问题的原因五花八门,属于疑难杂症之一。错误二:TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。对于错误二如果想不处理,可以直接在request.get()函数中加个timeout参数:eq = requests.get.原创 2021-01-22 23:15:41 · 47288 阅读 · 1 评论 -
TypeError: ‘set‘ object is not subscriptable
表示把不具有下标操作的集合对象用成了对象[i]集合(set)是Python中一种重要的数据类型,表示一组各不相同元素的无序集合,其主要应用于重复元素消除及关系测试等 集合在Python内部通过哈希表实现,其本征无序,输出时所显示的顺序具有随机性,且与运行环境相关...原创 2021-06-17 17:03:05 · 7476 阅读 · 0 评论 -
list转set遇坑:TypeError: unhashable type: ‘list‘
由list组成的list(list套list)是不能转set的,形如:datalist = [[a],[b]]转set时报错:TypeError: unhashable type: 'list'dataset = set(datalist)单层的list可以转set,形如:datalist = [1,2]dataset = set(datalist)原创 2021-06-24 17:01:09 · 1958 阅读 · 2 评论 -
报错:UnicodeDecodeError:: ‘utf-8‘ codec can‘t decode byte 0xc8 in position 0: invalid contin
python读取数据时出现:UnicodeDecodeError:: 'utf-8' codec can't decode byte 0xc8 in position 0: invalid contin解决方法一:f = open("xxx.csv",'r',encoding='UTF-8')解决方法二:f = open("xxx.csv","rb")with open('article.txt','rb') as f: # 打开新的文本 text_new = f.read(原创 2021-06-22 20:27:30 · 828 阅读 · 0 评论 -
AttributeError: ‘function‘ object has no attribute ‘sleep‘
time.sleep(t)语句执行报错错误如下:调了半天发现是一个低级错误,我又自己搞了一个time变量名称重复,把名称改了就好了。原创 2021-01-24 13:07:16 · 1493 阅读 · 0 评论 -
import遇错:AttributeError: module ‘numpy.random‘ has no attribute ‘default_rng‘
提示No module named 'gensim'说明没有该模块cmd中导入模块:pip install +模块C:\Users\Administrator>pip install gensim提示AttributeError: module 'numpy.random' has no attribute 'default_rng'问题原因:numpy版本问题升级numpy的版本在cmd下输入pip install -U numpyC:\Users\Admin..原创 2021-05-24 10:50:29 · 1897 阅读 · 0 评论 -
SyntaxError: invalid character in identifier
错误原因是代码中出现了中文的空格、中文的括号、不恰当的tab等非文字字符找了半天,所有字符均没有问题,最后发现是错误行末尾多打了空格,很难发现原创 2021-06-22 16:21:10 · 286 阅读 · 0 评论 -
ModuleNotFountError:No module named ‘gensim‘(在python代码中导入gensim模块)
运行窗口:conda install +模块pip install +模块第一个命令应该由于网速太慢没有下载完全,第二个命令我手动输入n退出了。网速慢,可以使用如下命令:pip install -i https://pypi.douban.com/simple gensimpip install -i https://pypi.tuna.tsinghua.edu.cn/simple gensimpip install -i https://pypi.douban.com/si原创 2021-01-14 23:32:17 · 8558 阅读 · 0 评论 -
reload(sys)报错:NameError: name ‘reload‘ is not defined
reload(sys)sys.setdefaultencoding('utf8')上为python2.x版本的写法,作用是:设置python的默认编码,一般设置为utf8的编码格式python3.x中改为:import importlib,sys importlib.reload(sys)原创 2021-06-22 16:13:23 · 2663 阅读 · 0 评论 -
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xa4 in position 4: illegal multibyte sequence
python读取txt文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 4: illegal multibyte sequence原创 2021-06-17 16:39:26 · 2132 阅读 · 0 评论 -
安装anaconda,配置,遇错(输入python后打开弹出windows应用商店)
卸载python开始-设置-应用-找到python-x.x.x,直接卸载安装anaconda原创 2021-06-09 17:26:02 · 970 阅读 · 2 评论